0

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.

Faisal
  • 1,332
  • 2
  • 13
  • 29
  • Found the best example from below link: https://github.com/springbyexample/spring-by-example/blob/master/android/android-client/src/main/java/ua/com/springbyexample/fragment/MainListFragment.java Hence the quest solved. – Faisal Mar 25 '16 at 13:12

4 Answers4

0

Sample :

textView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                /*do action */
                return false;
            }
        });
0

Put mVacationListView.setOnLongClickListener(this) into your code. Then you will be able to handle clicks using:

@Override
public boolean onLongClick(View v) {
    return false;
}
  • Current listener implementation `mSpamListView = getListView(); mSpamListView.setEmptyView(getActivity().findViewById(R.id.empty)); mSpamListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mSpamListView.setItemsCanFocus(false); mSpamListView.setOnItemClickListener(this); mSpamListView.setOnItemLongClickListener(this); mSpamListView.setMultiChoiceModeListener(this); ` – Faisal Mar 16 '16 at 05:34
  • It should be not in listener but in onCreateView or onAttach – Konstantins Bogdanovs Mar 16 '16 at 07:54
0

I think you want list item click in your fragment. Please try below code.

  1. Add this code in your adapter.

    mVacationListView.setOnLongClickListener(your fragment instance);
    
  2. Handle override method in your fragment.

    @Override
    public boolean onLongClick(View v) {
        return false;
    }
    

If you do like this then your list item long click listener will handle at your fragment.

Pang
  • 9,564
  • 146
  • 81
  • 122
EKN
  • 1,886
  • 1
  • 16
  • 29
  • can you refer any sample which I can made use of. Thanks – Faisal Mar 16 '16 at 05:37
  • Hi faisalm please check below link. Sample code also available. http://www.vogella.com/tutorials/AndroidListView/article.html – EKN Mar 16 '16 at 10:02
0

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

Faisal
  • 1,332
  • 2
  • 13
  • 29