mercredi 7 janvier 2015

CheckBox item in ListView

I have a ListView in my Application containing custom list items with text views and a checkbox.



<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#5d5d5d"
android:textStyle="bold" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#5d5d5d"
android:textStyle="bold" />

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_alignParentLeft="true" />


When I perform a click a onItemClickListener is called



lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
...
saveListID(id);
}

});


I want to perform a different Action when the CheckBox and not the item itself is clicked. But how can i get the action and the position of the item?


As adapter for the List I use the following:



BaseAdapter adapter = new SimpleAdapter(MainActivity.this, List,
R.layout.list_item,
new String[] { TAG_NAME, TAG_DATE }, new int[] {
R.id.name, R.id.date });

setListAdapter(adapter);




Aucun commentaire:

Enregistrer un commentaire