Wrong fragment in ViewPager receives onContextItemSelected call

前端 未结 5 1960
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 12:00

I have an app that shows a few fragments (of the same type) in a ViewPager and I\'m having some trouble with context menu items. (I\'m using the support library

5条回答
  •  [愿得一人]
    2020-11-28 12:33

    So this is some sort of idiotic design decision by Google or something that has just gone totally unconsidered. The simplest way to work around this is to wrap the onContextItemSelected call with an if statement like this:

    if (getUserVisibleHint()) {
        // Handle menu events and return true
    } else
        return false; // Pass the event to the next fragment
    

    The compatibility library in ActionBarSherlock 3.5 had a hack like this.

提交回复
热议问题