android - Fragment + swipe + drawermenu -


i realized "swipe " project between 2 fragments works. have project walking drawer menu. try link 2 following assembly code , contains mainactivity menu must become / fragment. many functions change language / writing .

there easy idea of plan

here code mainactivity :

    package thyroid.com.thyroidmenu;  import android.content.intent; import android.net.uri; import android.os.bundle; import android.support.design.widget.navigationview; import android.support.v4.app.fragment; import android.support.v4.app.fragmentactivity; import android.support.v4.widget.drawerlayout; import android.support.v7.app.actionbardrawertoggle; import android.support.v7.app.appcompatactivity; import android.support.v7.widget.toolbar; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.menuitem; import android.view.viewgroup; import android.widget.adapterview; import android.widget.button; import android.widget.framelayout; import android.widget.listview; import android.widget.relativelayout; import android.widget.textview; import android.widget.toast; import android.util.log; import android.view.menu;   import com.google.android.gms.appindexing.action; import com.google.android.gms.appindexing.appindex; import com.google.android.gms.common.api.googleapiclient;   public class mainactivity extends fragment { public drawerlayout drawerlayout; public toolbar toolbar;   /**  * attention: auto-generated implement app indexing api.  * see https://g.co/appindexing/androidstudio more information.  */ public googleapiclient client;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);     initnavigationdrawer();      // attention: auto-generated implement app indexing api.     // see https://g.co/appindexing/androidstudio more information.     client = new googleapiclient.builder(this).addapi(appindex.api).build();  }  public void initnavigationdrawer() {      navigationview navigationview = (navigationview) findviewbyid(r.id.navigation_view);     assert navigationview != null;     navigationview.setnavigationitemselectedlistener(new navigationview.onnavigationitemselectedlistener() {         @override         public boolean onnavigationitemselected(menuitem menuitem) {               int id = menuitem.getitemid();              switch (id) {                 case r.id.home:                     toast.maketext(getapplicationcontext(), "home", toast.length_short).show();                     drawerlayout.closedrawers();                     break;                 case r.id.connection:                      setcontentview(r.layout.activity_mainlogin);                      intent myintent = new intent(mainactivity.this, login.class);                     startactivity(myintent);                       drawerlayout.closedrawers();                     break;                 case r.id.settings:                     toast.maketext(getapplicationcontext(), "settings", toast.length_short).show();                     drawerlayout.closedrawers();                     break;                 case r.id.trash:                     toast.maketext(getapplicationcontext(), "trash", toast.length_short).show();                     drawerlayout.closedrawers();                     break;                 case r.id.logout:                     finish();               }             return true;         }     });     view header = navigationview.getheaderview(0);     textview tv_email = (textview) header.findviewbyid(r.id.tv_email);     tv_email.settext("thyroid.mobileapp@gmail.com");     drawerlayout = (drawerlayout) findviewbyid(r.id.drawer);      actionbardrawertoggle actionbardrawertoggle = new actionbardrawertoggle(this, drawerlayout, toolbar, r.string.drawer_open, r.string.drawer_close) {          @override         public void ondrawerclosed(view v) {             super.ondrawerclosed(v);         }          @override         public void ondraweropened(view v) {             super.ondraweropened(v);         }     };     drawerlayout.adddrawerlistener(actionbardrawertoggle);     actionbardrawertoggle.syncstate();  }  @override public void onstart() {     super.onstart();      // attention: auto-generated implement app indexing api.     // see https://g.co/appindexing/androidstudio more information.     client.connect();     action viewaction = action.newaction(             action.type_view, // todo: choose action type.             "main page", // todo: define title content shown.             // todo: if have web page content matches app activity's content,             // make sure auto-generated web page url correct.             // otherwise, set url null.             uri.parse("http://host/path"),             // todo: make sure auto-generated app url correct.             uri.parse("android-app://thyroid.com.thyroidmenu/http/host/path")     );     appindex.appindexapi.start(client, viewaction); }  @override public void onstop() {     super.onstop();      // attention: auto-generated implement app indexing api.     // see https://g.co/appindexing/androidstudio more information.     action viewaction = action.newaction(             action.type_view, // todo: choose action type.             "main page", // todo: define title content shown.             // todo: if have web page content matches app activity's content,             // make sure auto-generated web page url correct.             // otherwise, set url null.             uri.parse("http://host/path"),             // todo: make sure auto-generated app url correct.             uri.parse("android-app://thyroid.com.thyroidmenu/http/host/path")     );     appindex.appindexapi.end(client, viewaction);     client.disconnect(); }        @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          view mainactivity = inflater.inflate(r.layout.activity_main, container, false);         ((textview)mainactivity.findviewbyid(r.id.textview)).settext("ios");         return mainactivity;     }} 

and here errors bad writing :

my errors

how change setcontentview / getapplicationcontext / findviewbyid ... etc fit in fragment ?

do have make process fragments realize little montage (see picture 1) ? fragments seem practical , me in case useful later ...

thanks ;)

try getactivity().function_name() i.e. functions have mentioned in question , in fragment. not right way. can follow instructions given here drawer layout.

http://slidenerd.com/2015/07/22/android-design-support-library/


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -