【发布时间】:2011-08-19 05:17:00
【问题描述】:
我有一个带有标题的列表视图。列表标题中有一个“开始”按钮。对于它的点击,我需要在自定义适配器中调用一个自定义方法。如何在侧 onlick 列表中获取适配器引用?
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;
}
}
【问题讨论】:
标签: android android-listview adapter