I am programming my first android app. For test purposes I show a list of objects (class cElement) at the mainactivity.
public class cElement {
private Integer Id;
private String Name;
private String Description;
private Boolean Checked;
....
}
The ListView is linked with a custom adapter to the list. The custom adapter extends the BaseAdapter and I inflate the layout of each element from the list.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/id"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@+id/standard"
android:textSize="20dp"
android:layout_weight="1">
</TextView>
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@+id/standard"
android:textSize="20dp"
android:layout_weight="2">
</TextView>
<TextView
android:id="@+id/description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@+id/standard"
android:textSize="20dp"
android:layout_weight="3">
</TextView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
android:id="@+id/checkBox"/>
</LinearLayout>
First question: Now I would like to check all CheckBoxes in one step with a button. What is good style?
- I update the list directly and call the notifyDataSetChanged method of the adapter
- I create a method checkall() within the adapter and call it from outside.
Second question: I would like to know which CheckBox is checked. So I create an eventhandler setOnClickListener and save the position in a variable within the adapter. Is this the right way?