-2

I have a LongClick method that launches a Fragment and is working fine:

@Override
public void onItemLongClick(int position, View view) {

    Bundle bundle = new Bundle();
    bundle.putInt("itemPosition",position);        
    android.app.FragmentManager fm = getFragmentManager();
    DeleteCFragment delCDialog = new DeleteCFragment();
    delCDialog.setArguments(bundle);
    delCDialog.show(fm,"delcardview dialog");
}

Is there any speed or other advantage to setting up the method with a boolean like this?

@Override
public boolean onItemLongClick(int position, View view) {

    Bundle bundle = new Bundle();
    bundle.putInt("itemPosition",position);        
    android.app.FragmentManager fm = getFragmentManager();
    DeleteCFragment delCDialog = new DeleteCFragment();
    delCDialog.setArguments(bundle);
    delCDialog.show(fm,"delcardview dialog");
    return true;
}
AJW
  • 1,578
  • 3
  • 36
  • 77
  • in first case you must have to return boolean value as function rerurning boolean – N J Sep 21 '16 at 03:25
  • 1
    Possible duplicate - http://stackoverflow.com/questions/12230469/android-why-does-onitemlongclick-return-a-boolean – Veener Sep 21 '16 at 03:30
  • @Veener Hi, I understand return true versus return false for a boolean. What I am trying to determine is whether to use the boolean (the second example) or just run the first example shown without a boolean. – AJW Sep 21 '16 at 03:33

1 Answers1

1

The official documentation says:

return true if the callback consumed the long click, false otherwise

https://developer.android.com/reference/android/widget/AdapterView.OnItemLongClickListener.html

  • yes but the first example shown above runs fine without any boolean. I am trying to determine whether to use first example without a boolean or the second example with a boolean. – AJW Sep 21 '16 at 03:27
  • The API documentation recommends returning boolean so you should follow it. Option #2. – Veener Sep 21 '16 at 03:29
  • 1
    If your views has other listeners like onClickListener or onTouchListener, you need to use the boolean return to verify longClick event happens. Otherwise abstract method is ok. – Andres Vasquez Agramont Sep 21 '16 at 03:31
  • @Andres Vasquez Agramont Ah, that makes sense. Answer upvoted and accepted, cheers. – AJW Sep 21 '16 at 03:36