leave a comment
  1. Lance Johnson

    Well done Sr. You really hit the mark on this one. I would just add one thing to support tooltip on long press. I got that via:

    TooltipCompat.setTooltipText(rootView, alertMenuItem .getTitle())

    in onPrepareOptionsMenu when you add the other click listener.

  2. Faris M S

    Good Article, Thanks for writing this.
    i have tried this one in my Fragment, But it is getting error for invoking custom control
    “java.lang.NullPointerException: Attempt to invoke virtual method ‘android.view.View android.widget.FrameLayout.findViewById(int)’ on a null object reference”

    • Hi Faris,

      Without looking at your code there are a number of things that could cause that. My top guesses are: your menu items might not have the same id names, and you might not have called setHasOptionsMenu(true).

      I can say for certain that the FrameLayout you are calling findViewById() on is null and that is, somehow, the cause of the issue.
      This example uses Activity instead of Fragment, you’ll need to make the appropriate adjustments to the implementation.

      Hope this helps!

Leave a Reply

Your email address will not be published. Required fields are marked *