0
在使用基於BaseAdapter的自定義ListView時,如何爲上下文菜單註冊ListView?我試過registerForContextMenu(getListView());
,但這似乎不起作用。我使用API Demos中的ListView14.java。如何實現自定義ListView的上下文菜單?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new EfficientAdapter(this));
registerForContextMenu(getListView());
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.tag_context_menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.tagView:
// editNote(info.id);
return true;
case R.id.tagRename:
// deleteNote(info.id);
return true;
case R.id.tagDelete:
// deleteNote(info.id);
return true;
default:
return super.onContextItemSelected(item);
}
}