Пожалуйста, проверьте следующий код с помощью этого можно создать контекстное меню Внутри Listview ::
Функция Создать
@Override
public boolean onContextItemSelected(MenuItem item) {
int menuItemId = item.getItemId();
//to find out the id
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
int currentSelectionItemPosition = menuInfo.position;
//moving the cursor to the selected position in the list view
restaurantFavoritesCursor.moveToPosition(currentSelectionItemPosition);
int restaurantid = restaurantFavoritesCursor.getInt(idColumnIndex);
if(menuItemId == R.id.deleteFavoriteRestaurant)
{
//write the Action
}
return true;
}
Зарегистрируйте событие в OnCreate или Внутри OnStart
registerForContextMenu (listviewobject);
попробуйте приведенный выше код. Надеюсь, он сработает.
введите код –
Вы обрабатываете событие onContextItemSelected правильно? – waqaslam