نمایش اطلاعات در ویوپیجر و فراگمنت توسط تب

بدون ترجمه با یک نگاه گذار دستتون میاد که چجوری اطلاعت وفراگمنت(fragment) را  توسط یک ویوپیجر(viewpager) و تب(PagerTabStrip) قابل نمایش می سازد  سوالی بود در خدمتم

In this tutorial, you will learn how to create a PagerTabStrip in your Android application. PagerTabStrip is intended to be used as a child view of a ViewPager widget in your XML layout. PagerTabStrip is most often used with fragment, which is a convenient way to supply and manage the Lifecycle of each fragment. We will create a PagerTabStrip with custom titles and tabs and on flip left or right or tab click will show different fragments. So lets begin…

Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project PagerTabStripTutorial.

Application Name : PagerTabStripTutorial

Project Name : PagerTabStripTutorial

Package Name : com.androidbegin.pagertabstriptutorial

Open your MainActivity.java and paste the following code.

MainActivity.java

In this activity, we have set the location and the ViewPagerAdapter into the ViewPager. Then pass the support fragment manager into ViewPagerAdapter to manage the fragments.

Next, create an XML graphical layout for the MainActivity. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file activity_main.xml and paste the following code.

activity_main.xml

Next, create the first fragment tab. Go to File > New > Class and name it FragmentTab1.java. Select your package named com.androidbegin.pagertabstriptutorial and click Finish.

Open your FragmentTab1.java and paste the following code.

Next, create the second fragment tab. Go to File > New > Class and name it FragmentTab2.java. Select your package named com.androidbegin.pagertabstriptutorial and click Finish.

Open your FragmentTab2.java and paste the following code.

FragmentTab2.java

Next, create the third fragment tab. Go to File > New > Class and name it FragmentTab3.java. Select your package named com.androidbegin.pagertabstriptutorial and click Finish.

Open your FragmentTab3.java and paste the following code.

FragmentTab3.java

Next, create a ViewPager Adapter class. Go to File > New > Class and name it ViewPagerAdapter.java. Select your package named com.androidbegin.pagertabstriptutorial and click Finish.

Open your ViewPagerAdapter.java and paste the following code.

ViewPagerAdapter.java

In this ViewPagerAdapter class, we have declared the number of ViewPager pages and on tab switch or flip will show different fragments.

Next, create an XML graphical layout for first fragment tab. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file fragmenttab1.xml and paste the following code.

fragmenttab1.xml

Next, create an XML graphical layout for second fragment tab. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file fragmenttab2.xml and paste the following code.

fragmenttab2.xml

Next, create an XML graphical layout for third fragment tab. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file fragmenttab3.xml and paste the following code.

fragmenttab3.xml

Change the application name and fragment textview texts in strings.xml. Open your strings.xml and paste the following code. Go to res > values > strings.xml

In your AndroidManifest.xml, no changes needed to be made.

AndroidManifest.xml

Output

:

PagerTabStrip ScreenShots
سایت اصلی مطلب

شاید این مطالب را هم دوست داشته باشید

پاسخ دهید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *