android - Updating fragments/views in viewpager with fragmentStatePagerAdapter -
need problem of updating pages while using viewpager. using simple viewpager fragmentstatepageradapter. want access current fragment/view can update textviews in fragment/view. searched around in forum , came know few things - 1 of ways handle setting tag in instantiateitem() call of adapter , retreive view findviewbytag. not understand how implement , not sure if work fragmentstatepageradapter. - explored other options suggested in various forums, cannot make them work.
my code same in android http://developer.android.com/training/animation/screen-slide.html. basic components same (fragment activity xml display components including textview, viewpager xml view pager in it, fragment class , main fragmentactivity class). in fragmentactivity class have added pagechangelistener viewpager can textview changes during onpageselected().
any is appreciated.
adding code reference.
public class myactivity extends fragmentactivity //variable declarations protected void oncreate(bundle savedinstancestate) { viewpager mpager = (viewpager) findviewbyid(r.id.pager); mpageradapter = new screenslidepageradapter(getsupportfragmentmanager()); mpager.setadapter(mpageradapter); view currview; onpagechangelistener pagechangelistener = new onpagechangelistener() { @override public void onpageselected(int pageselected) { dotextviewchnges();//access text view , update based on pageselected ---this stuck in trying textview in current fragmwnt/view------- } mpager.setonpagechangelistener(pagechangelistener); } private class screenslidepageradapter extends fragmentstatepageradapter { public screenslidepageradapter(android.support.v4.app.fragmentmanager fm) { super(fm); } @override public android.support.v4.app.fragment getitem(int position) { return screenslidepagefragment.create(position, <other parameters want pass>); } @override public int getcount() { return num_pages; } }
in onpagechangelistener:
onpagechangelistener pagechangelistener = new onpagechangelistener() { @override public void onpageselected(int pageselected) { screenslidepagefragment currentfragment = (screenslidepagefragment) mpageradapter.getitem(pageselected) dotextviewchnges();//access text view , update based on pageselected ---this stuck in trying textview in current fragmwnt/view------- }
Comments
Post a Comment