onItemClick两个列表视图问题 [英] onItemClick Two Listviews problem

查看:124
本文介绍了onItemClick两个列表视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个活动二列表视图。他们都触发此:

I have two listviews in the same activity. They both trigger this:

public void onItemClick(AdapterView adapter, View v, int position, long arg3) 

如何检查从这个事件处理程序中选择哪个列表?
此外,如果适配器==为listA 然后我需要在该列表和位置的复选框被选中/未选中。我如何做到这一点从这里我的活动范围内的?

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?

也许是这样的: v.myCheckBox.setChecked(假)< - 显然是行不通

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);

要知道是谁创建的视图最简单的方法就是存储一些标识符由适配器(View.setTag()方法)创建的视图的标记字段。在适配器的getView方法创建新的视图时,这应该被设置。然后从view.getTag(),你将能够看到的适配器创造了它,并作出适当的反应。

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

和你只有在B1创建的视图复选框,然后你应该得到的东西一样,在B1:

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
}

这篇关于onItemClick两个列表视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆