我的日记-弹出全局菜单
1、为某一个view对象注册全局菜单 registerForContextMenu(view); 2、创建全局菜单 // 创建全局菜单
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
3、全局菜单中某一项被选择 // 一个全局菜单项被选择
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
int position = (int) info.id;
Note note = (Note) subjectlist.getItemAtPosition(position);
NoteEntry entry = note.getNoteEntry();
switch (item.getItemId()) {
case R.id.menu_add_note:// 添加日记
Intent intent = new Intent(this, NewDiaryActivity.class);
startActivityForResult(intent, 0);
return true;
case R.id.menu_delete_note:// 删除日记
deleteNote(entry);
return true;
case R.id.menu_edit_note:// 编辑日记
return true;
}
return super.onContextItemSelected(item);
}
|
效果: |
|