android - Adapt chrisbanes ActionBar-PullToRefresh to Fragments(NavigationDrawer) -
okay here problem:
i want implement chrisbanes actionbar-pulltorefresh library fragments able use navigationdrawer.
https://github.com/chrisbanes/actionbar-pulltorefresh#fragments
.
chrisbanes says use fragments:
one thing note pulltorefreshattacher needs created in oncreate() phase of activity. if plan on using library fragments best practice activity create pulltorefreshattacher, , have fragments retrieve activity.
an example provided in fragment & tabs sample.
.
.
****here comes question: created pulltorefreshattacher in activity how hell pass pulltorefreshattacher fragments :s****
i have read bundles , getarguments() putserializable , parcelable :
and read article in sth. ((myactivity ) getactivity()).getclassx() ;
used.
but nothing understood/worked. :(
.
.
here navigationactivity , 1 example fragment.i have new android/java :)
final string[] menuentries = {"start","datum","website","kunden"}; final string[] fragments = { "com.blabla.mainfragment", "com.blabla.onefragment", "com.blabla.twofragment", "com.blabla.kundenfragment", }; private actionbardrawertoggle drawertoggle; private drawerlayout draweradapter; private listview navlistadapter; private pulltorefreshattacher mpulltorefreshattacher; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.navigation_layout); mpulltorefreshattacher = pulltorefreshattacher.get(this); arrayadapter<string> adapter = new arrayadapter<string>(getactionbar().getthemedcontext(), android.r.layout.simple_list_item_1, menuentries); final drawerlayout drawer = (drawerlayout)findviewbyid(r.id.refresh_navwiev); final listview navlist = (listview) findviewbyid(r.id.drawermenu); draweradapter=drawer; navlistadapter=navlist; getactionbar().setdisplayhomeasupenabled(true); getactionbar().sethomebuttonenabled(true); drawertoggle = new actionbardrawertoggle( this, drawer, r.drawable.navicon, r.string.drawer_open, r.string.drawer_close ) { /** called when drawer has settled in closed state. */ public void ondrawerclosed(view view) { } /** called when drawer has settled in open state. */ public void ondraweropened(view drawerview) { } }; drawer.setdrawerlistener(drawertoggle); navlist.setadapter(adapter); navlist.setonitemclicklistener(new onitemclicklistener(){ @override public void onitemclick(adapterview<?> parent, view view, final int pos,long id){ drawer.setdrawerlistener( new drawerlayout.simpledrawerlistener(){ @override public void ondrawerclosed(view drawerview){ super.ondrawerclosed(drawerview); //runs on completly closed } }); //runs onclick if not same fragment if(getactionbar().gettitle()!= menuentries[pos]) { bundle bundle=new bundle(); bundle.putstring("message", "from activity"); //fragment zusammenbauen fragment myfragment=new fragment(); myfragment = fragment.instantiate(navigationactivity.this, fragments[pos]); myfragment.setarguments(bundle); fragmenttransaction tx = getsupportfragmentmanager().begintransaction(); tx.setcustomanimations(r.anim.fragmentfadein, r.anim.fragmentfadeout); tx.replace(r.id.navigationscreen, myfragment); tx.commit(); getactionbar().settitle(menuentries[pos]); drawer.closedrawer(navlist); } } }); bundle bundle=new bundle(); // bundle.putint(pulltorefreshattacher., position); //fragment zusammenbauen fragment myfragment=new fragment(); myfragment = fragment.instantiate(navigationactivity.this, fragments[0]); myfragment.setarguments(bundle); fragmenttransaction tx = getsupportfragmentmanager().begintransaction(); tx.setcustomanimations(r.anim.fragmentfadein, r.anim.fragmentfadeout); tx.replace(r.id.navigationscreen, myfragment); tx.commit(); } public boolean onkeyup(int keycode, keyevent event) { if (keycode == keyevent.keycode_menu) { log.i("flostemplate", "menu taste gedrückt"); if(draweradapter.isdraweropen(navlistadapter)) { draweradapter.closedrawer(navlistadapter); } else { draweradapter.opendrawer(navlistadapter); } return true; } return super.onkeyup(keycode, event); } @override protected void onpostcreate(bundle savedinstancestate) { super.onpostcreate(savedinstancestate); drawertoggle.syncstate(); } @override public void onconfigurationchanged(configuration newconfig) { super.onconfigurationchanged(newconfig); drawertoggle.onconfigurationchanged(newconfig); } @override public boolean onoptionsitemselected(menuitem item) { if (drawertoggle.onoptionsitemselected(item)) { return true; } return super.onoptionsitemselected(item); } @override public boolean oncreateoptionsmenu(menu menu) { getmenuinflater().inflate(r.menu.main, menu); return true; } }
and fragment
public class mainfragment extends fragment { public static fragment newinstance(context context) { mainfragment f = new mainfragment(); return f; } @override public view oncreateview(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_main, container, false); return rootview; } }
it kind if me ,i stuck @ point days :)
p.s. sorry bad language , not native speaker ;)
there demo code on github page:
add activity:
public pulltorefreshattacher getpulltorefreshattacher() { return mpulltorefreshattacher; }
and oncreateview in fragment:
pulltorefreshattacher mpulltorefreshattacher = ((navigationactivity) getactivity()).getpulltorefreshattacher();
a better approach use interface i'd recommend starting github example.
Comments
Post a Comment