android - Refreshing data display on a fragment -
i have 2 fragments on view pager. once had move data fragment b , refresh data displayed on , did getitemposition. reason, same method doesn't work when try reset data..
in adapter have :
public void refresh() { notifydatasetchanged(); } @override public int getitemposition( object obj ) { return position_none; }
in fragment click 'reset' :
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); nottriedpasswordslist = pageractivity.mainlist; ..... .... resetbutton.setonclicklistener( new view.onclicklistener() { @override public void onclick( view v ) { pageractivity.resetpasswords(); pageractivity.viewpageradapter.refresh(); }});
viewpager activity hosting both fragments:
public static void resetpasswords() { mainlist.addall( 0, historylist ); historylist.clear(); pageractivity.viewpageradapter.refresh(); }
main fragment pass displayed :
@override public view oncreateview( layoutinflater inflater, viewgroup container, bundle savedinstancestate ) { view view = inflater.inflate(r.layout.fragment_main, container, false); ..... nextcodedisplay = ( textview ) view.findviewbyid( r.id.passworddisplaytextview ); nextcodedisplay.settext( nottriedpasswordslist.get( 0 ).getpasswordstring() ); .... nextbutton.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { nottriedpasswordslist.remove( 0 ); if( nottriedpasswordslist.size() > 0 && !(nottriedpasswordslist.get( 0 ).gettried()) ) { nextcodedisplay.settext( nottriedpasswordslist.get( 0 ).getpasswordstring() ); } }
pageractivity
treated static class, , can access static methods , member data , objects in way. code:
nottriedpasswordslist = pageractivity.mainlist;
note: pageractivity
can access static mainlist
object, or nottriedpasswordslist
(sharing same memory). object can access since code references static methods.
on code pageractivity.viewpageradapter.refresh()
, not clear on data refreshes since don't see enough code, again refresh()
must static method. code notifydatasetchanged
(), there must direct link between viewpageradapter
, data object, arraylist. don't see direct relation between two.
perhaps want code like:
viewpageradapter pageradapter = new viewpageradapter();
this way can have relationship between adapter , possibly arraylist object. benefit of creating instance new saves data , state inside class in form of object, in sample pageradapter
.
i not suggest specific set of codes since don't see sufficient amount of me fix. perhaps can fix code first , can contribute.
Comments
Post a Comment