Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long click on ListFragment

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 OnItemLongClickListener() for an Activity). How can I use this in my fragment?

Thanks!

like image 240
tsync Avatar asked Jul 18 '11 12:07

tsync


1 Answers

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!

like image 60
Narayanan Avatar answered Sep 22 '22 19:09

Narayanan