Android: Context menu on single click

前端 未结 4 796
借酒劲吻你
借酒劲吻你 2020-12-28 14:51

I have an Intent that extends a ListActivity. In my onCreate method after having populated the list adapter I use registerForContextMenu(getListView());

4条回答
  •  渐次进展
    2020-12-28 15:39

    Here is another simpler way to show context menu on single click.

    private void addOnClickListener()
    {
        contactList.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            public void onItemClick(AdapterView parent, View view, int position, long id)
            {
                  view.showContextMenu();
            }
        })
    }
    

    replace contactList by your ListView and make sure to call this method after the initialization of ListView.

提交回复
热议问题