Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select middle page of FragmentPagerAdapter?

Tags:

android

I've to invoke 3rd page of view-pager using FragmentPagerAdapter so I've passed value 3 to this fragment activity which loads view-pager. But It invokes still first page of page-viewer. Any solution will be appreciated.

like image 937
Vishwanath Deshmukh Avatar asked Jul 05 '13 09:07

Vishwanath Deshmukh


People also ask

What can I use instead of FragmentPagerAdapter?

This class is deprecated. Switch to androidx. viewpager2. widget.

What is the difference between FragmentPagerAdapter and FragmentStatePagerAdapter?

FragmentPagerAdapter is used exactly like FragmentStatePagerAdapter . It only differs in how it unloads your fragments when they are no longer needed (Figure 11.4). With FragmentStatePagerAdapter , your unneeded fragment is destroyed.

How do I refresh Fragmentstateadapter?

You can use startActivityForResult(or broadcast/receiver) to get the result from the activity. Then use adapter. notifyDataSetChanged to refresh the fragment.

What is a view pager?

ViewPager in Android allows the user to flip left and right through pages of data. In our android ViewPager application we'll implement a ViewPager that swipes through three views with different images and texts.


1 Answers

just use

mViewPager.setCurrentItem(2);

if you want to go to 3rd page, because the index starts with 0.

like image 154
Neoh Avatar answered Oct 29 '22 01:10

Neoh