获取列表视图标题按钮的 onlick listner 内的适配器引用
我有一个带有标题的列表视图。列表标题中有一个“前往”按钮。对于其单击,我需要调用自定义适配器中的自定义方法。如何在 side onlick lister 中获取适配器参考?
public class GroupListActivity extends ListActivity {
...
private void createGroupList() {
final ListView listView = getListView();
final View view = getLayoutInflater().inflate(R.layout.multi_list_groups_header, listView, false);
listView.addHeaderView(view, null, true);
TextView listHeader = (TextView) findViewById(R.id.groupsHeader);
Button goButton = (Button) findViewById(R.id.goButton);
this.gAdapter = new GroupAdapter(this, R.layout.multi_list_groups2, gStore, true);
this.setListAdapter(this.gAdapter);
//listView.setFocusable(false);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
goButton = (Button) findViewById(R.id.goButton);
goButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e(MY_DEBUG_TAG,"Manual Go!!");
// I need to call the adapters' getCheckedItems() method here
}
});
}
定制适配器
public class GroupAdapter extends ArrayAdapter<Group> {
...
public HashMap<String, String> getCheckedItems() {
return checkedItems;
}
}
I've a list view with a header. There is a 'Go' button in the list header. And for its on click I need to call a custom method in the Custom Adapter. How can I get the Adapter reference in side onlick lister?
public class GroupListActivity extends ListActivity {
...
private void createGroupList() {
final ListView listView = getListView();
final View view = getLayoutInflater().inflate(R.layout.multi_list_groups_header, listView, false);
listView.addHeaderView(view, null, true);
TextView listHeader = (TextView) findViewById(R.id.groupsHeader);
Button goButton = (Button) findViewById(R.id.goButton);
this.gAdapter = new GroupAdapter(this, R.layout.multi_list_groups2, gStore, true);
this.setListAdapter(this.gAdapter);
//listView.setFocusable(false);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
goButton = (Button) findViewById(R.id.goButton);
goButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e(MY_DEBUG_TAG,"Manual Go!!");
// I need to call the adapters' getCheckedItems() method here
}
});
}
Custom Adapter
public class GroupAdapter extends ArrayAdapter<Group> {
...
public HashMap<String, String> getCheckedItems() {
return checkedItems;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您想创建一个自定义
Button
来保存GroupAdapter
的引用。这样,您就可以将传入的View
对象强制转换为自定义Button
,然后获取您的GroupAdapter
。Perhaps you want to create a custom
Button
that holds on to a reference of yourGroupAdapter
. That way, you can cast the passed inView
object to your customButton
, and then get yourGroupAdapter
.