Adam Gardner Adam Gardner - 3 months ago 12
Android Question

Multiple clicks on same ViewPagerAdapter

I am using a ViewPager and have a custom Adapter. I have 3 layouts to create a small widget at the bottom of my home screen. I am able to add widgets inside them and have the whole viewpager clickable but only able to get 1 click event for the whole widget.

Is it possible to have 2 textviews on same layout within the viewpager that can be clicked and send the user to different Activities/Fragments?

I have set each textview to clickable and the viewpager itself but still only getting 1 trigger event no matter which textview I click within the viewpager.

Answer

Is it possible to have 2 textviews on same layout within the viewpager that can be clicked and send the user to different Activities/Fragments?

Yes. You can create a Fragment for the layout which can hold whatever views you want. Then add an OnClickListener to each TextView and perform whatever action you wish. Consider using Buttons instead of TextViews. Users will expect to be able to click on a Button but clicking on a TextView isn't as common.

Comments