EDIT: Based on evolution of the problem, I edited this question.
So the problem is: I want to populate a ListView with checkboxes, and as I want to customize my ListView I'm not using simple_multiple_choice_mode, I'm putting my layout on list_item.xml: (for each row)
<checkbox>
xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="8mm"
android:layout_width="fill_parent"
android:layout_height="wrap_removed" android:id="@+id/nomeAPP" style="?listItem">
</checkbox>
My ListView is on lista.xml
<ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_height="wrap_content"
style="?whiteBackground">
</ListView>
my adapter:
list=getListView();
this.setListAdapter(new ArrayAdapter<String>(this,
R.layout.list_item, aux));
So I'm trying to make a setOnCheckedChangeListener for the checkboxes, so I can store the chosed items in an array.
So I did this listener based on the answer below:
CheckBox cb = (CheckBox) findViewById(R.id.CheckBox01);
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (buttonView.isChecked()) {
Toast.makeText(getBaseContext(), "Checked",
Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "UnChecked",
Toast.LENGTH_SHORT).show();
}
}
});
Problem is: I get the NULL exception. The
CURIOUS thing is: if I "switch" my layout for a simple
<ScrollView android:id="@+id/widget54" android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<CheckBox android:text="Checkbox" android:id="@+id/CheckBox01"
android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</LinearLayout>
</ScrollView>
And forget my ListView, it works! So, what's wrong with my layout?
I created a new little project just to let you guys see exactly the situation. It's available
here[
^] Right now does not work, but if you uncomment the adapter, change ListActivity to Activity and change setContentView, it will work (checked/unchecked toast text).
Another curious thing I found is that with ListActivity does not work never.... wondering if it's related...