Android ViewPager can not load 3rd Fragment -
i have encourage problem when load 3 fragments viewpager each time started activity, there 2 fragments (fragment 1 & fragment 2) loaded. dont know why fragment 3 not been load.
below code
activity
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_register_testing); // load pager data viewpager = (viewpager) findviewbyid(r.id.pagertestingregister); list<fragment> fragments = new arraylist<>(); fragments.add(new fragment1()); fragments.add(new fragment2()); fragments.add(new fragment3()); viewpager.setadapter(new registertestingfragmentpageradapter(getsupportfragmentmanager(), fragments));
}
activity ui
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/expense1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" tools:context=".expense1"> <tabhost android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/tabhost"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <horizontalscrollview android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/scrolltabhost" android:fillviewport="true" android:scrollbars="none"> <tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="bottom"></tabwidget> </horizontalscrollview> <framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v4.view.viewpager android:layout_width="match_parent" android:layout_height="match_parent" android:persistentdrawingcache="all" android:id="@+id/pagertestingregister"> </android.support.v4.view.viewpager> </framelayout> </linearlayout> </tabhost>
adapter
public class registertestingfragmentpageradapter extends fragmentpageradapter { list<fragment> fragments; public registertestingfragmentpageradapter(fragmentmanager fragmentmanager, list<fragment> fragments){ super(fragmentmanager); this.fragments = fragments; } public registertestingfragmentpageradapter(fragmentmanager fragmentmanager){ super(fragmentmanager); //this.fragments = fragments; } @override public android.support.v4.app.fragment getitem(int position) { return fragments.get(position); } @override public int getcount() { return fragments.size(); }
}
Comments
Post a Comment