ViewPager OnLongClick监听器不点火监听器、ViewPager、OnLongClick

2023-09-08 09:30:15 作者:旧忆▲Eros1o

我有一个包含ViewPager片段。当我吹的布局,我分配一个OnLongClick监听器,如下所示:

I have a fragment which contains a ViewPager. When I inflate the layout, I assign an OnLongClick listener to it as follows:

mPager.setOnLongClickListener(mOnPagerLongClickListener);

然而,当我在ViewPager执行长按,什么都不会发生。我能做些什么,使这项工作?或者,我需要听众分配给在ViewPager改为每看法?分配监听到的V​​iewPager包含GridView的似乎不工作的。

However, when I perform a long click on the ViewPager, nothing happens. What can I do to make this work? Or do I need to assign the listener to every view in the ViewPager instead? Assigning the listener to the GridViews which the ViewPager contains doesn't seem to work either.

推荐答案

有关穿上查询借口,但我能解决这个问题。它不会对你有所帮助,但可能会派上用场的其他任何浏览器。

Excuse for putting on a query, but I am able to solve the issue. It won't be helpful to you but may come in handy for any other viewer.

最简单的解决方法是直接将监听器的ImageView对象而其分配给ViewPager的对象,即,分配viewPager.setOnLongClickListener不会触发任何东西。

The simple solution is to assign listener directly to ImageView's object rather assigning it to ViewPager's object, i.e, assigning viewPager.setOnLongClickListener will not fire anything.

因此​​,我们必须在延长)通过PageAdapter在instantiateItem(类onLongClickListeners初始化ImageView的:

So, we have to initialize ImageView with onLongClickListeners in the class extending PageAdapter in instantiateItem() by:

imageView.setOnLongClickListener(new OnLongClickListener()){

    @Override
    public boolean onLongClick(View v) {
        // Do your stuff
        return false;
    }
});
 
精彩推荐
图片推荐