Android ListView 长按列表弹出菜单

时间:2014-05-14 07:17:56   收藏:0   阅读:360

Android ListView 长按列表弹出菜单

设置长按菜单

bubuko.com,布布扣
listView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {           
  @Override
   public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
     menu.add(0, 0, 0, "删除单号");  
     menu.add(0, 1, 1, "接收此单");   
   }
});
bubuko.com,布布扣

 

监听菜单单击事件

bubuko.com,布布扣
    @Override  
    public boolean onContextItemSelected(MenuItem item) {  
        Log.d("TEST", item.getTitle().toString());
        if(item.getMenuInfo() instanceof AdapterContextMenuInfo) {
            AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
            Log.d("TEST", info.position+"--");
        }
        return super.onContextItemSelected(item);  
    } 
bubuko.com,布布扣


当上下文菜单是通过AdapterView创建的,那么AdapterViewAdapterContextMenuInfo这个类可以获取当前长按的Item,可以获取长按行的id,position,targetView

bubuko.com,布布扣

Android ListView 长按列表弹出菜单,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!