Android Studio SwipeView Pager Adapter

In this Android Studio article iam going to show you creating SwipeView Pager Adapter.

So  for good explanation you can watch the video for this article.

 

Also check my Android Development Courses

 

So now lets get started !

1: First of all create a new project in your Android Studio, and choose Empty Activity

also iam using API 20 for this project

2: In the second step you need to create Fragment and call it MyFragment.

3: OK now you need to create a FragmentAdapter.java class

so this is the code for FragmentAdapter.java class.

OK at the code you can see that we have extended our class from FragmentStatePagerAdapter, after extend

you need to implement some methods,  the first one is getItem(), this is the place that we are going to get the items

and also we send a bundle data to our fragment.

also the second method is getCount(), and we are going to create 50 fragment for this project .

 

 

 

So now in the layout folder open your activity_main.xml file, and add a ViewPager in that file.

after adding the file will looks like this.

 

 

And in our fragment_my.xml we are going to just add a TextView.

 

So now open MyFragment.java file and we need to extend the class from Fragment.

and also in CreateView method we need to inflate our layout.

 

 

 

At the end you need to open your main_activity.java and create the object of FragmentAdaper and also

find the id of viewpager, this is the code for our this java file.

 

 

Run the complete project and swipe the view this will be the result

Android Studio SwipeView Pager Adapter
Android Studio SwipeView Pager Adapter

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

Codeloop
Share via
Copy link
Powered by Social Snap
×