2009年1月15日 星期四

使用ListView的Long Click Menu

正式名稱是「ContextMenu」

1.
在ListActivity的onCreate內呼叫registerForContextMenu(getListView());

2.
Override以下方法:
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn)
一樣用menu.add(...)方法來註冊Long click menu的選項
接著用((AdapterContextMenuInfo) menuInfoIn).position來取得被點選的List Item的position(我是用member field存起來)

3.
Override以下方法:
public boolean onContextItemSelected(MenuItem item)
和一般選單一樣,switch item的getItemId()再對應做事即可

沒有留言:

CODE { display: block; /* fixes a strange ie margin bug */ font-family: Courier New; font-size: 8pt; overflow:auto; background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) left top repeat-y; border: 1px solid #ccc; padding: 10px 10px 10px 21px; max-height:200px; height:200px; // for IE6 line-height: 1.2em; } #quote { display: block; /* fixes a strange ie margin bug */ font-family: Verdana; font-size: 10pt; overflow:auto; background: #f7f7f7 url(http://lh5.ggpht.com/_z-VThISftkI/SXUlpyfw9ZI/AAAAAAAABYY/e3GUx9_Z4TE/s288/quote-l.gif) left top no-repeat; border: 4px dotted #ccc; padding: 15px 15px 15px 31px; /*up right bottom left*/ max-height:300px; line-height: 1.2em; }