• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Viewpager

Hello!

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:eek:rientation="vertical"
tools:context="com.androidmads.customurlscheme.MainActivity">

<android.support.v4.view.ViewPager android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"></android.support.v4.view.ViewPager>

</LinearLayout>

MainActivity.java
.....
ViewPager viewPager = findViewById(R.id.viewpager);
PagerAdapter pagerAdapter = new PagerAdapter() {
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);

@override
public int getCount() {
return 5;
}

@override
public Object instantiateItem(ViewGroup container, int position) {
View view =layoutInflater.inflate(R.layout.textview_layout, container, false);
((TextView)view).setText(position+"");
container.addView(view);
return view;
}

@override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View)object);
}

@override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
};
viewPager.setAdapter(pagerAdapter);
...
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones