我们已经创建了列表视图,但其中一行有三个子项。子项包含ID、名称、电话号码。我想使用ID how to get that ID(子项)删除记录。我告诉过你我可以找到行的位置,但找不到ID(子项)。

public void onCreateContextMenu(ContextMenu menu, View v,


            ContextMenuInfo menuInfo) {

        super.onCreateContextMenu(menu, v, menuInfo);
        menu.add(0, v.getId(), 0, "Edit");
        menu.add(0, v.getId(), 0, "Delete");
        menu.add(0, v.getId(),0,"Cancel");
    }



public boolean onContextItemSelected( MenuItem item){


                 super.onContextItemSelected(item);

         if(item.getTitle()=="Delete"){

                 AdapterContextMenuInfo info = (AdapterContextMenuInfo)        item.getMenuInfo();
               //find the position of row

       long id= getListView().getItemIdAtPosition(info.position);


              //please write the code here how to get subitem id
         }
}

最佳答案

试试这个:

 int itemId = item.getItemId();

它将返回菜单项ID

关于android - 如何从 ListView 中删除子项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12650552/

10-11 02:20