Android open ContextMenu on short click + pass item clicked details

后端 未结 6 628
不思量自难忘°
不思量自难忘° 2020-12-03 03:19
 lv.setOnItemClickListener(new OnItemClickListener() {
             @Override
          public void onItemClick(AdapterView parent, View view, int position,         


        
6条回答
  •  时光取名叫无心
    2020-12-03 03:36

    Regarding opening a context menu on a short click:

    The other solutions posted here didn't work for me because I was using a ListFragment. However the following solution seems to work quite nicely for both a ListFragment and a ListActivity (or just any old listview in general):

    public void onListItemClick(ListView l, View v, int position, long id){
      l.showContextMenuForChild(v);   
    }
    

    It's much more simple and elegant. In fact, this is actually how the ListView class itself initiates the context menu on a long click.

提交回复
热议问题