In last chapter we had created Tabs with Fragments Now we will have swipe Gesture with our tabs. We still do not have swipe gestures yet.For this we will be using ViewPager You can think ViewPager roughly as a listView in horizontal.
Lets start by adding ViewPager to our layout for MainActivity,we be using code from previous post,
Now replace
<FrameLayout android:id="@+android:id/realtabcontent" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" />this with
<android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" />This will make us replace
mTabManager = new TabManager(this, mTabHost, android.R.id.tabcontent);
Notice again here we are again using Androids default Tab content
Now we add ViewPager to our activity
this.mViewPager = (ViewPager) super.findViewById(R.id.viewpager);
ViewPager must have an Adapter similar to the way ListView does. We do not have any functionality to add so we ll keep it simple
public class PagerAdpater extends FragmentPagerAdapter { private List<Fragment> fragmentList; public PagerAdpater(FragmentManager fm, List<Fragment> fragmentList) { super(fm); this.fragmentList = fragmentList; } /* * (non-Javadoc) * * @see android.support.v4.app.FragmentPagerAdapter#getItem(int) */ @Override public Fragment getItem(int position) { // TODO Auto-generated method stub return fragmentList.get(position); } /* * (non-Javadoc) * * @see android.support.v4.view.PagerAdapter#getCount() */ @Override public int getCount() { // TODO Auto-generated method stub return fragmentList.size(); } }The adapter must extend FragmentPagerAdapter
Our Adapter will also be managing change of Tabs and ViewPager's page so
implements OnTabChangeListener, ViewPager.OnPageChangeListener { /** * Initialise ViewPager */ private void initViewPager() { List<Fragment> fragments = new Vector<Fragment>(); fragments .add(Fragment.instantiate(this, FragmentA.class.getName())); fragments .add(Fragment.instantiate(this, FragmentB.class.getName())); this.mPagerAdapter = new PagerAdpater( super.getSupportFragmentManager(), fragments); this.mViewPager = (ViewPager) super.findViewById(R.id.viewpager); this.mViewPager.setAdapter(this.mPagerAdapter); this.mViewPager.setOnPageChangeListener(this); Constants.log(TAG, "intialiseViewPager"); }
Thanks. Any chance for tutorial about how to swipe element in a list view? Such as Gmail app?
ReplyDeleteAmazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live.
ReplyDeleteIT Institute in KK nagar | mobile App Development Training in Chennai | Android Development Training in Chennai | Ios App Development Training in Chennai
And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
ReplyDeleteJmeter training in chennai | best jmeter training in chennai | jmeter training institute in chennai | jmeter training institute in chennai KK Nagar
php training institute in chennai | php training in chennai |best php training institute in chennai |php course in chennai |best php training in chennai | best php training in chennai KK Nagar
angularjs training in chennai | angularjs course in chennai |angularjs training institute in chennai |angularjs training institutes in chennai | angularjs training institutes in chennai KK Nagar
Best selenium training institute in chennai | selenium course in chennai | selenium training institute in chennai | selenium classes in chennai | selenium testing training in chennai |selenium certification in chennai | selenium certification in chennai KK Nagar
Fantastic!! you are doing good job! I impressed. Many bodies are follow to you and try to some new.. After read your comments I feel; Its very interesting and every guys sahre with you own works. Great!!
ReplyDeleteve may bay di nhat ban
vé máy bay tết giá rẻ 2021
vé máy bay giá rẻ đi đà nẵng tháng 11
bay từ sài gòn ra nha trang mất bao lâu
mua vé máy bay giá rẻ đi quy nhơn
Wynn Las Vegas - Dr.MCD
ReplyDeleteWynn is 창원 출장마사지 one of the most 광주 출장샵 recognizable brands in Las Vegas, so 1xbet many of the rooms When I check 경기도 출장샵 in and see Wynn Las Vegas, I 진주 출장안마 feel like I've seen an