0
我已經創建了一個對話框,在那個對話框中我有一個列表視圖。我爲該listView創建了一個上下文菜單。它顯示上下文菜單,但當我點擊該上下文菜單項時,它不起作用。如何創建列表視圖的上下文菜單
任何人都可以請幫我解決這個問題。
我已經創建了一個對話框,在那個對話框中我有一個列表視圖。我爲該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);
嘗試上面的代碼,我希望它能工作。
提供您的代碼 – 2012-01-16 08:55:55
您是否正確處理onContextItemSelected事件? – waqaslam 2012-01-16 09:19:09