1 / 4

ListView + 長按選單

ListView + 長按選單. 建國科技大學 資管系 饒瑞佶 2012/4. 長按選單. 與建立 menu 的方式相似 加入 onCreateContextMenu 和 onContextItemSelected( 選單則是需要 onCreateOptionsMenu 與 onOptionsItemSelected) 在 oncreate 內註冊 Listview 在 onCreate() 時加入 registerForContextMenu() 方法 registerForContextMenu(ListView)

dante-hicks
Download Presentation

ListView + 長按選單

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ListView + 長按選單 建國科技大學 資管系 饒瑞佶 2012/4

  2. 長按選單 • 與建立menu的方式相似 • 加入onCreateContextMenu和onContextItemSelected(選單則是需要onCreateOptionsMenu與onOptionsItemSelected) • 在oncreate內註冊Listview • 在onCreate()時加入registerForContextMenu()方法 • registerForContextMenu(ListView) • onContextItemSelected() 裡加入 AdapterContextMenuInfo 來取得使用者點選的項目 AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); //取得選取資訊 switch(item.getItemId()) { case MENU_BUTTON_1: break; case MENU_BUTTON_2: break; }

  3. onCreateContextMenu menu.setHeaderTitle("要如何處理這個項目?");//設定長按選單的表頭 menu.add(0, MENU_ABOUT, 0, "修改"); menu.add(0, MENU_QUIT, 0, "刪除");

  4. onContextItemSelected AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();//取得Listview選取資訊 switch(item.getItemId()) { case MENU_ABOUT: break; case MENU_QUIT: break; }

More Related