Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onclick on view pager in android does not work in my code

i have implemented view pager in my code and i have put on-click listener on view pager but my on-click listener does not working i'll post my code

viewpager.setOnClickListener(new OnClickListener() 
{
    @Override
    public void onClick(View v) 
    {
        Log.i("***","***");
        Toast.makeText(getActivity(), "XXXX", Toast.LENGTH_SHORT).show();
    }
});
like image 215
Achin Avatar asked Feb 18 '14 06:02

Achin


People also ask

What is the use of ViewPager in Android?

Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows. ViewPager is most often used in conjunction with android.

How do I add a button to a view pager?

just use Relative layout as parent layout and align the button at the bottom... like floating action button.. (layout_alignParentBottom = true) xml if you want that button to be visible in all pages of pager..

What does onClick mean in Android Studio?

OnClickListener, you can defined your click of each button in method public void onClick(View v) . Keyword this refer to the method onclick. It is good to use this way when there are a lot of button in your class file.


1 Answers

Use clicklistener inside the item of ViewPager. This is not working because Child of ViewPager is intercepting event of parent(i.e ViewPager). E.G if you are adding ImageView inside ViewPager using PagerAdapter then use click of ImageView to make it simple

like image 141
Tofeeq Ahmad Avatar answered Oct 11 '22 14:10

Tofeeq Ahmad