Long click on ListFragment

前端 未结 3 723
醉梦人生
醉梦人生 2021-02-05 01:44

I\'m working with a ListFragment and doing a onListItemClick. Everything works fine, but now I want to use a long Item Click (e.g setOnItemLongClickListener(new OnItemLongClickL

3条回答
  •  情话喂你
    2021-02-05 02:37

    Yes, the solution posted by tsync works for me. I too had ran into same problem and considered that this is not possible. I tried the above suggestion as follows:

    public  class ProjectsFragment extends ListFragment {
    
    @Override
    public void onActivityCreated(Bundle savedState) {
        super.onActivityCreated(savedState);
    
        getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
    
            @Override
            public boolean onItemLongClick(AdapterView arg0, View arg1,
                    int arg2, long arg3) {
                Toast.makeText(getActivity(), "On long click listener", Toast.LENGTH_LONG).show();
                return true;
            }
        });
    

    and it worked!

提交回复
热议问题