Search code examples
androidandroid-listfragmentcontextual-action-barlong-pressuilongpressgesturerecogni

OnItemLongClickListener() doesn't result in log tap gesture in ListFragment


Long tap gesture not working in ListFragment in combination with AdapterView.OnItemLongClickListener. I'm trying to achieve the GMail like long-tap selection and continuous selection on upcoming single taps.

The ListFragment declared as below:

public class VacationListFragment extends ListFragment implements View.OnClickListener, 
    ActionMode.Callback, AdapterView.OnItemClickListener, 
    AdapterView.OnItemLongClickListener, AbsListView.MultiChoiceModeListener, {

ListFragment loads the data from DB with SimpleCursorAdapter as below:

mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.vacationlist_row_item, null, 
                  fromColumns, toView, 0);
mVacationListView.setAdapter(mAdapter);

Current scenario:

on single the CAB shows up with provided menu(delete) and the action is working. Screenshot pasted below:

Screenshot here

I believe we're very close to solution and any input would be appreciated. Feel free to ping if I'm not pedagogical. Thanks.


Solution

  • I could solve the issue with below code sample. It's Good example for Multi-select list for ListFragment in conjunction with LoaderCallbacks and MultiChoiceModeListener.

    https://github.com/springbyexample/spring-by-example/blob/master/android/android-client/src/main/java/ua/com/springbyexample/fragment/MainListFragment.java