Skip to content Skip to sidebar Skip to footer

Onitemclick Two Listviews Problem

I have two listviews in the same activity. They both trigger this: public void onItemClick(AdapterView adapter, View v, int position, long arg3) How do I check which list was sel

Solution 1:

For getting the checkbox - it's best to use something like that:

checkbox = (Checkbox) view.findViewById(R.id.yourcheckboxid);
checkbox.setChecked(false);

The easiest way to know who created a view is to store some kind of identifier in Tag field of the view created by the adapter (View.setTag() method). This should be set when the new view is created in getView method of the adapter . Then from view.getTag() you will be able to see which adapter created it and react appropriately.

Although from what you write you should do it differently (if you inherit adapter anyway). If your adapter hierarchy is:

A -> B1
  \
   B2

And you have checkboxes only in views created in B1, then you should get something like that in B1:

@OverridepublicvoidonItemClick(AdapterView adapter, View v, int position, long arg3) {
   super.onItemClick(adapter,v,position,arg3);
   checkbox = (Checkbox) view.findViewById(R.id.yourcheckboxid);
   checkbox.setChecked(false);
   ... any other custom handling for list handled by B1
}

Solution 2:

to check which view pass user view.getId()

Post a Comment for "Onitemclick Two Listviews Problem"