spentak
spentak

Reputation: 4737

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 selected from this event handler? Also, if adapter == listA then I need the checkbox in that list and position to be selected/unselected. How do I do this from within my activity here?

Maybe something like: v.myCheckBox.setChecked(false) <-- obviously that doesn't work.

Note: I am using two custom adapters that inherit from base adapter.

Upvotes: 0

Views: 1146

Answers (2)

neeraj t
neeraj t

Reputation: 4764

to check which view pass user view.getId()

Upvotes: 0

Jarek Potiuk
Jarek Potiuk

Reputation: 20097

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:

@Override
public void onItemClick(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
}

Upvotes: 1

Related Questions