Checkbox checked or not cannot be logged
I am an android learner, I have a task from my course to write into the log when a checkbox is clicked.
My XML is:
<CheckBox
android:id="@+id/whippedCreamCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped Cream"
android:textSize="16sp"
android:paddingLeft ="24dp"
android:buttonTint="#008000"
android:textAppearance="?android:textAppearanceMedium" />
And corresponding java code is
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox);
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
The remaining code builds, runs and functions without errors. However, in the log I cannot see the desired output. But I see
Not supplying enough data to HAL, expected position 4798584 , only
wrote 4798080
You can access the entire log here https://gist.github.com/latrociny/f318f74bbf9b9e28cc0a3a5370eaf996
android
add a comment |
I am an android learner, I have a task from my course to write into the log when a checkbox is clicked.
My XML is:
<CheckBox
android:id="@+id/whippedCreamCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped Cream"
android:textSize="16sp"
android:paddingLeft ="24dp"
android:buttonTint="#008000"
android:textAppearance="?android:textAppearanceMedium" />
And corresponding java code is
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox);
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
The remaining code builds, runs and functions without errors. However, in the log I cannot see the desired output. But I see
Not supplying enough data to HAL, expected position 4798584 , only
wrote 4798080
You can access the entire log here https://gist.github.com/latrociny/f318f74bbf9b9e28cc0a3a5370eaf996
android
when is this function called? on checkbox click?
– ahuja007
Nov 20 '18 at 16:44
No I did not create any other function to call this. Should I create another method to call this method?
– Kay
Nov 20 '18 at 16:50
You should call this function or otherwise how will you reach log printing statement
– ahuja007
Nov 20 '18 at 16:52
add a comment |
I am an android learner, I have a task from my course to write into the log when a checkbox is clicked.
My XML is:
<CheckBox
android:id="@+id/whippedCreamCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped Cream"
android:textSize="16sp"
android:paddingLeft ="24dp"
android:buttonTint="#008000"
android:textAppearance="?android:textAppearanceMedium" />
And corresponding java code is
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox);
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
The remaining code builds, runs and functions without errors. However, in the log I cannot see the desired output. But I see
Not supplying enough data to HAL, expected position 4798584 , only
wrote 4798080
You can access the entire log here https://gist.github.com/latrociny/f318f74bbf9b9e28cc0a3a5370eaf996
android
I am an android learner, I have a task from my course to write into the log when a checkbox is clicked.
My XML is:
<CheckBox
android:id="@+id/whippedCreamCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped Cream"
android:textSize="16sp"
android:paddingLeft ="24dp"
android:buttonTint="#008000"
android:textAppearance="?android:textAppearanceMedium" />
And corresponding java code is
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox);
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
The remaining code builds, runs and functions without errors. However, in the log I cannot see the desired output. But I see
Not supplying enough data to HAL, expected position 4798584 , only
wrote 4798080
You can access the entire log here https://gist.github.com/latrociny/f318f74bbf9b9e28cc0a3a5370eaf996
android
android
asked Nov 20 '18 at 16:36
KayKay
5311
5311
when is this function called? on checkbox click?
– ahuja007
Nov 20 '18 at 16:44
No I did not create any other function to call this. Should I create another method to call this method?
– Kay
Nov 20 '18 at 16:50
You should call this function or otherwise how will you reach log printing statement
– ahuja007
Nov 20 '18 at 16:52
add a comment |
when is this function called? on checkbox click?
– ahuja007
Nov 20 '18 at 16:44
No I did not create any other function to call this. Should I create another method to call this method?
– Kay
Nov 20 '18 at 16:50
You should call this function or otherwise how will you reach log printing statement
– ahuja007
Nov 20 '18 at 16:52
when is this function called? on checkbox click?
– ahuja007
Nov 20 '18 at 16:44
when is this function called? on checkbox click?
– ahuja007
Nov 20 '18 at 16:44
No I did not create any other function to call this. Should I create another method to call this method?
– Kay
Nov 20 '18 at 16:50
No I did not create any other function to call this. Should I create another method to call this method?
– Kay
Nov 20 '18 at 16:50
You should call this function or otherwise how will you reach log printing statement
– ahuja007
Nov 20 '18 at 16:52
You should call this function or otherwise how will you reach log printing statement
– ahuja007
Nov 20 '18 at 16:52
add a comment |
1 Answer
1
active
oldest
votes
Add this attribute to the CheckBox
:
android:onClick="indicateBoxChecked"
and change your code to this (it is inside your activity class isn't it?):
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = (CheckBox) v;
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
now whenever you click the CheckBox
, the method indicateBoxChecked()
will be executed.
I guess the variable TAG
has been initialized.
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay you don't need findViewById because the parameterv
is the clicked View.
– forpas
Nov 20 '18 at 17:02
@Kay you just have to castv
to aCheckBox
– forpas
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397537%2fcheckbox-checked-or-not-cannot-be-logged%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add this attribute to the CheckBox
:
android:onClick="indicateBoxChecked"
and change your code to this (it is inside your activity class isn't it?):
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = (CheckBox) v;
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
now whenever you click the CheckBox
, the method indicateBoxChecked()
will be executed.
I guess the variable TAG
has been initialized.
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay you don't need findViewById because the parameterv
is the clicked View.
– forpas
Nov 20 '18 at 17:02
@Kay you just have to castv
to aCheckBox
– forpas
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
add a comment |
Add this attribute to the CheckBox
:
android:onClick="indicateBoxChecked"
and change your code to this (it is inside your activity class isn't it?):
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = (CheckBox) v;
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
now whenever you click the CheckBox
, the method indicateBoxChecked()
will be executed.
I guess the variable TAG
has been initialized.
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay you don't need findViewById because the parameterv
is the clicked View.
– forpas
Nov 20 '18 at 17:02
@Kay you just have to castv
to aCheckBox
– forpas
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
add a comment |
Add this attribute to the CheckBox
:
android:onClick="indicateBoxChecked"
and change your code to this (it is inside your activity class isn't it?):
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = (CheckBox) v;
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
now whenever you click the CheckBox
, the method indicateBoxChecked()
will be executed.
I guess the variable TAG
has been initialized.
Add this attribute to the CheckBox
:
android:onClick="indicateBoxChecked"
and change your code to this (it is inside your activity class isn't it?):
public void indicateBoxChecked(View v) {
CheckBox whippedCreamCheckBox = (CheckBox) v;
boolean checked = whippedCreamCheckBox.isChecked();
Log.v(TAG, "Checkbox value is " + checked );
}
now whenever you click the CheckBox
, the method indicateBoxChecked()
will be executed.
I guess the variable TAG
has been initialized.
answered Nov 20 '18 at 16:53
forpasforpas
11.1k3423
11.1k3423
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay you don't need findViewById because the parameterv
is the clicked View.
– forpas
Nov 20 '18 at 17:02
@Kay you just have to castv
to aCheckBox
– forpas
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
add a comment |
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay you don't need findViewById because the parameterv
is the clicked View.
– forpas
Nov 20 '18 at 17:02
@Kay you just have to castv
to aCheckBox
– forpas
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
Can you please tell why did you not do CheckBox whippedCreamCheckBox = findViewById(R.id.whippedCreamCheckBox); ? yes it is inside activity class and TAG is initialized
– Kay
Nov 20 '18 at 17:00
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay so now you see the log message?
– forpas
Nov 20 '18 at 17:01
@Kay you don't need findViewById because the parameter
v
is the clicked View.– forpas
Nov 20 '18 at 17:02
@Kay you don't need findViewById because the parameter
v
is the clicked View.– forpas
Nov 20 '18 at 17:02
@Kay you just have to cast
v
to a CheckBox
– forpas
Nov 20 '18 at 17:03
@Kay you just have to cast
v
to a CheckBox
– forpas
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
hi this is fixed, thanks. I see now 2018-11-20 18:02:13.819 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true 2018-11-20 18:02:27.220 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is false 2018-11-20 18:02:28.943 8019-8019/com.example.android.justjava V/MainActivity: Checkbox value is true
– Kay
Nov 20 '18 at 17:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397537%2fcheckbox-checked-or-not-cannot-be-logged%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
when is this function called? on checkbox click?
– ahuja007
Nov 20 '18 at 16:44
No I did not create any other function to call this. Should I create another method to call this method?
– Kay
Nov 20 '18 at 16:50
You should call this function or otherwise how will you reach log printing statement
– ahuja007
Nov 20 '18 at 16:52