[英]listview with kopokami in each row, how to handle a click on them?
There is a list of listview, in each row is a button that, when clicked on it to display in this row has one button (delete). 有一个listview列表,在每一行中都有一个按钮,当单击它以显示在该行中时,有一个按钮(删除)。 I'm still new to android. 我还是Android新手。 Tell me how to organize such a behavior, not quite sure how to determine when you click on the button to which line they belong. 告诉我如何组织这种行为,不太确定如何确定何时单击按钮时它们属于哪一行。
You said that you have a delete button in every list row in the listview. 您说在列表视图的每个列表行中都有一个删除按钮。 I assume that you have a custom layout for the row then. 我假设您为行设置了自定义布局。 If you have implemented this custom layout in a custom list adapter you have the getView() method in the adapter where you inflate the layout into the row. 如果已在自定义列表适配器中实现了此自定义布局,则在适配器中具有getView()方法,可在其中将布局膨胀到行中。 There you can edit the id of the button like this: 您可以在此处编辑按钮的ID,如下所示:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Button b = (Button) convertView.findViewById(R.id.button);
// here the id
b.setId(position);
return v;
}
When you get the onclick somewhere in your app you can access the source of the event and get the id. 当您在应用中的某处获取onclick时,您可以访问事件的源并获取ID。
I don't know if this is a good way to implement it and if it meets your needs but it is a simple solution. 我不知道这是否是实现它的好方法,并且它是否满足您的需求,但这是一个简单的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.