Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid, Checkbox listener in XML?
    primarykey
    data
    text
    <p>It's possible, to do things like this</p> <p>XML:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/addContactButton" android:text="@string/addContactButtonLabel" android:onClick="launchContactAdder"/&gt;&lt;!-- here --&gt; &lt;/LinearLayout&gt; </code></pre> <p>Java:</p> <pre><code>public void launchContactAdder(View v) { Intent i = new Intent(this, ContactAdder.class); startActivity(i); } </code></pre> <p>but there is a requirement, that the method must be public, void and the most important take View as an argument.</p> <p>Now i'd like to do exactly the same thing but with Checkbox button. Checkbox has android:onclick attribute, but in Android tutorial (http://developer.android.com/resources/samples/ContactManager/index.html) I can see this code</p> <pre><code>showInvisibleControl.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Log.d(TAG, "mShowInvisibleControl changed: " + isChecked); showInvisible = isChecked; populateContactList(); } }); </code></pre> <p>So there is a onCheckedChanged(CompoundButton buttonView, boolean isChecked) method. Is there any way to do this by XML? There's no android:onCheckedChange attribute, only android:onClick attribute, but as I wrote above, name of that attribute must have corresponding method name, which takes View as an argument, but from the code above I understand that i must have a method with CompoundButton and boolean arguments.</p> <p>Any way to do that in "XML way"?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload