android - Navigation drawer lag -
the navigation drawer lags every time open new activity. looked on google solution , found out can solve delaying new activity handler. experimented little bit got nowhere.
some code pieces mainactivity.java:
public void selectitem(int possition) { fragment fragment = null; bundle args = new bundle(); switch (possition) { case 2: fragment = new fragmentzero(); break; case 3: fragment = new fragmentone(); break; case 4: fragment = new fragmenttwo(); break; case 5: fragment = new fragmentthree(); break; case 7: fragment = new fragmenttwo(); break; case 8: fragment = new fragmentzero(); break; case 9: fragment = new fragmentone(); break; case 10: fragment = new fragmenttwo(); break; case 11: fragment = new fragmentzero(); break; case 12: fragment = new fragmentone(); break; case 14: fragment = new fragmentzero(); break; case 15: fragment = new fragmentone(); break; case 16: fragment = new fragmenttwo(); break; default: break; } fragment.setarguments(args); fragmentmanager frgmanager = getfragmentmanager(); frgmanager.begintransaction().replace(r.id.content_frame, fragment) .commit(); mdrawerlist.setitemchecked(possition, true); settitle(datalist.get(possition).getitemname()); mdrawerlayout.closedrawer(mdrawerlist); }
and
private class draweritemclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { if (datalist.get(position).gettitle() == null) { selectitem(position); } } }
in activity create handler , initialize in on create method
private handler mhandler; mhandler = new handler();
then change drawer item click listener this.
private class draweritemclicklistener implements listview.onitemclicklistener { @override public void onitemclick(adapterview<?> parent, view view, final int position, long id) { if (datalist.get(position).gettitle() == null) { mhandler.postdelayed(new runnable() { @override public void run() { selectitem(position);; } }, 250); } mdrawerlist.setitemchecked(possition, true); mdrawerlayout.closedrawer(mdrawerlist); } }
and change selectitem method this
public void selectitem(int possition) { fragment fragment = null; bundle args = new bundle(); switch (possition) { case 2: fragment = new fragmentzero(); break; case 3: fragment = new fragmentone(); break; case 4: fragment = new fragmenttwo(); break; case 5: fragment = new fragmentthree(); break; case 7: fragment = new fragmenttwo(); break; case 8: fragment = new fragmentzero(); break; case 9: fragment = new fragmentone(); break; case 10: fragment = new fragmenttwo(); break; case 11: fragment = new fragmentzero(); break; case 12: fragment = new fragmentone(); break; case 14: fragment = new fragmentzero(); break; case 15: fragment = new fragmentone(); break; case 16: fragment = new fragmenttwo(); break; default: break; } fragment.setarguments(args); fragmentmanager frgmanager = getfragmentmanager(); frgmanager.begintransaction().replace(r.id.content_frame, fragment) .commit(); settitle(datalist.get(possition).getitemname()); }
Comments
Post a Comment