开发者

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 select开发者_Python百科ed 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.


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
}


to check which view pass user view.getId()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜