1
我有一個標題列表視圖。列表頭中有一個'Go'按鈕。而對於它的點擊,我需要在自定義適配器中調用一個自定義方法。我怎樣才能獲得側面onlick列表中的適配器參考?獲取適用於listview標題按鈕的onlick listner中的Adapter參考
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;
}
}
如何在自定義按鈕中引用適配器? –
如果您定義構造函數以接納適配器,那麼您可以保留其參考。 –