[英]Android List View - receive click event on separate item in listview row
I have a List View in which I inflate for each item a linear layout. 我有一个列表视图,在其中为每个项目充气一个线性布局。 This linear layout contains 2 relative layouts.
此线性布局包含2个相对布局。 In each of these 2 relative layouts I included another layout using so the list will display 2 elements per row.
在这2个相对布局的每一个中,我都使用另一个布局,因此该列表每行将显示2个元素。 How can I know on which of those 2 elements the user clicked?
我如何知道用户点击了这两个元素中的哪个?
I think your problem may be resolved if you assign events for both elements. 我认为如果您为两个元素都分配事件,则可能会解决您的问题。 In the getView method of your adapter, you need to assign the clickListener event and set the tag to both views.
在适配器的getView方法中,您需要分配clickListener事件并将标记设置为两个视图。 For instance:
例如:
relativeLayout1.setOnClickListener(yourClickListener);
relativeLayout1.setTag(yourPositionTag);
relativeLayout2.setOnClickListener(yourClickListener);
relativeLayout2.setTag(yourPositionTag);
This way, you are able to detect which view was selected in your onClick method: 这样,您就可以检测在onClick方法中选择了哪个视图:
public void onClick(View v) {
yourTag = v.getTag();
switch (v.getId()) {
case R.id.relativeLayout1:
// your code here
break;
case R.id.relativeLayout2:
// your code here
break;
}
Hope this help! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.