【发布时间】:2013-02-04 13:24:42
【问题描述】:
我有一个片段,里面有一个列表视图。
listview 使用自定义适配器。列表视图中的每个项目都包含一个按钮。
我需要的是让活动知道我在列表视图中按下了什么按钮。我需要这个,因为片段也需要根据按下的按钮向其活动发送消息。所以基本上我希望OnClickListener 在片段中而不是在适配器中。
我试图通过遍历所有元素并执行 getChild() 从列表中获取按钮,但它对点击没有反应。
Button theButton = (Button)theListView.getChildAt(i).findViewById(R.id.button_id);
我也尝试过使用适配器上的 getView。
Button theButton = (Button) adapter.getView(i, null, null).findViewById(R.id.button_id);
【问题讨论】:
标签: java android listview button adapter