I already had success on create the floating context menu when I long click one item on list view. However, when I click the menu on context menu there is nothing happening. I want to make it to start a new activity. Is there something wrong?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_view);
dataSource = new DBDataSource(this);
dataSource.open();
values = dataSource.getAllMahasiswa();
ArrayAdapter<Mahasiswa> adapter = new ArrayAdapter<Mahasiswa>
(this, android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
listView=(ListView) findViewById(android.R.id.list);
registerForContextMenu(listView);
}
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, 1000, 0, "Edit");
menu.add(0, 1001, 0, "Hapus");
}
public boolean onContextMenuItemSelected(MenuItem item){
switch (item.getItemId()) {
case 1000:
Intent i = new Intent(ActivityView.this, Tes.class);
startActivity(i);
break;
case 1001:
//not yet
break;
}
return super.onContextItemSelected(item);
}
Use this
with
create image_options.xml in menu folder of resource.