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);
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.
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.
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;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With