java - Android : Acess pagerAdapter layout listview with ViewPager and AsyncTask -
i have pageradapter :
public class apppageradapter extends pageradapter { context context; public apppageradapter(context appcon) { this.context = context; } @override public int getcount() { return 10; } @override public object instantiateitem(viewgroup container, int position) { view viewitem = inflater.inflate(r.layout.pager_layout, container, false); listview listview = (listview) viewitem.findviewbyid(r.id.list); } }
and in xml : "pager_layout.xml"
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" xmlns:wheel="http://schemas.android.com/apk/res-auto" android:layout_height="match_parent"> <listview android:layout_width="wrap_content" android:id="@+id/list" android:divider="@color/activity_background" android:layout_height="match_parent"> </listview>
and, main fragment page :
public class apps extends fragment { public apps() {} @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { mroot = inflater.inflate(r.layout.app_activity, container, false); viewpager pager = (viewpager)mroot.findviewbyid(r.id.view_pager); apppageradapter appadapter = new apppageradapter(getactivity()); pager.setadapter(appadapter); pager.setonpagechangelistener(new viewpager.onpagechangelistener() { @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { } @override public void onpageselected(int position) { //access position list view add adapter new loading().execute; //async task data , add list view pager } @override public void onpagescrollstatechanged(int state) {} }); } }
now, how can access view on screen page adding data page?
want add data listview of page selected.
please me .
if viewpager have 4 fragments: a,b,c,d. , open fragment a. fragment b , d create automatically viewpager.
and if want add data listview. let see method:
@override public object instantiateitem(viewgroup container, int position) { view viewitem = inflater.inflate(r.layout.pager_layout, container, false); listview listview = (listview) viewitem.findviewbyid(r.id.list); }
what
int position?
it page selected - openning. above code create 10 page in viewpager, each page have listview. if want add data this, write more code in method
instantiateitem()
Comments
Post a Comment