这个需求应该比较常见了,就是list列表长按菜单项所对应的listitem的id是多少,如何得到。 网上应该也有很多,不过多解释在此记录
- public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfoIn) {
- AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfoIn;
-
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)aItem.getMenuInfo();
- 这个mi对象中会有 id position view三个参数
- }
- span style="font-family: Tahoma;font-size:10px;"> 还有可能是这样的</span>
- public boolean onContextItemSelected(MenuItem aItem) {
- ContextMenuInfo menuInfo = (ContextMenuInfo) aItem.getMenuInfo();
- AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)aItem.getMenuInfo();
- id = (int)info.id;
- return true;
- }
列表长按菜单对应的选项ID
原文:http://www.cnblogs.com/ywq-come/p/5925615.html