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;
}
}
Perhaps you want to create a custom
Buttonthat holds on to a reference of yourGroupAdapter. That way, you can cast the passed inViewobject to your customButton, and then get yourGroupAdapter.