Tôi có chế độ xem danh sách chứa dữ liệu. Tôi thiết lập một menu ngữ cảnh cho listview sử dụng đoạn mã sau:Android: Cách tìm vị trí được nhấp từ menu ngữ cảnh
list.setOnCreateContextMenuListener
(
new View.OnCreateContextMenuListener()
{
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo)
{
AdapterContextMenuInfo mi =(AdapterContextMenuInfo) menuInfo;
menu.add(0, 0, 0, "Delete item");
}
}
);
Tôi có override phương pháp sau đây để kiểm soát de ContextMenu menuitem chọn:
@Override
public boolean onContextItemSelected(MenuItem item)
{
switch(item.getItemId())
{
case 0:
ShowAlert("hello from delete item");
break;
default:
return super.onContextItemSelected(item);
}
return true;
}
Trong phương pháp overrided này, làm thế nào có thể tôi tìm mục của chế độ xem danh sách đã được nhấp?
Xin cảm ơn trước. Trân trọng. Jose
Cảm ơn rất nhiều. Trân trọng. jose – Sosi
thông tin luôn luôn là rỗng trong trường hợp của tôi .. bất cứ ai có thể giúp đỡ? Tôi đang sử dụng GridView. –
Cuối cùng tôi đã làm việc đó, tôi đã sử dụng GridView tùy chỉnh trong đó phương thức 'getContextMenuInfo()' không được triển khai. Tôi đã đăng [ở đây] (http://vinaybhargav.wordpress.com/2014/07/20/android-floating-context-menu-for-listviewgridview/) trong trường hợp nếu ai đó cần một mẫu. –