android - DrawerLayout populating menus from other activity -
i'am creating menu 2 navigation drawers 1 in each side:
everything working should want separate populating tasks main activity left activity , right activity, on had separeted layouts (just better struture)
this main layout:
<!-- main content view --> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:context=".mainactivity" > <listview android:id="@+id/main_list_viewer" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:divider="@android:color/darker_gray" android:dividerheight="1dp" android:footerdividersenabled="true" android:paddingleft="1dp" > </listview> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:text="@string/hello_world" /> </relativelayout> <!-- left navigation drawer --> <include layout="@layout/activity_left" /> <!-- right navigation drawer --> <include layout="@layout/activity_right" />
and left drawer layout:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#111" android:orientation="vertical" > <linearlayout android:id="@+id/buttons_linear_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <imagebutton android:id="@+id/login_image_button" android:layout_width="50dip" android:layout_height="50dip" android:contentdescription="@string/login_image" android:src="@drawable/ic_launcher" /> <imagebutton android:id="@+id/logout_image_button" android:layout_width="50dip" android:layout_height="50dip" android:contentdescription="@string/login_image" android:src="@drawable/ic_launcher" /> </linearlayout> <listview android:id="@+id/left_list_viewer" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" android:choicemode="singlechoice" android:divider="@android:color/black" android:dividerheight="0dp" > </listview>
now populated left navigation drawer listviewer dummies.
public class leftactivity extends sherlockactivity implements onclicklistener{ private listview leftlistview; private arrayadapter<string> listadapter; // session manager class sessionmanager session; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_left); movetasktoback(true); leftlistview = (listview) findviewbyid(r.id.left_list_viewer); // create , populate list of planet names. string[] planets = new string[] { "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune" }; arraylist<string> planetlist = new arraylist<string>(); planetlist.addall(arrays.aslist(planets)); // create arrayadapter using planet list. listadapter = new arrayadapter<string>(this, r.layout.simplerow, planetlist); // add more planets. if passed string[] instead of list<string> // arrayadapter constructor, must not add more items. // otherwise exception occur. listadapter.add("ceres"); listadapter.add("pluto"); listadapter.add("haumea"); listadapter.add("makemake"); listadapter.add("eris"); // set arrayadapter listview's adapter. leftlistview.setadapter(listadapter); // onclicklistener's button, after pressed send // onclick method button pressed imagebutton loginimagebutton = (imagebutton) findviewbyid(r.id.login_image_button); loginimagebutton.setonclicklistener(this); imagebutton logouimagebutton = (imagebutton) findviewbyid(r.id.logout_image_button); logouimagebutton.setonclicklistener(this); } // method decide what button pressed public void onclick(view v) { session = new sessionmanager(getapplicationcontext()); switch (v.getid()) { case r.id.login_image_button: if (session.isloggedin() == false) { intent intent = new intent(getapplicationcontext(), loginactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); } else { log.d("moodydebud", "entrará aqui se o utilizador ja estiver logado e em vez de vir para aqui irá para defeniçoes de utilizador"); } break; case r.id.logout_image_button: if (session.isloggedin() == true) { session.logoutuser(); } else { // só entra neste else caso o utilizador ainda nao esteja // loggado entao é reencaminhado para o loginactivity intent intent = new intent(getapplicationcontext(), loginactivity.class); intent.setflags(intent.flag_activity_clear_top); startactivity(intent); } break; default: throw new runtimeexception("unknown button id"); } }
}
but problem when start mainactivity leftactivitity it's not initialized , listview empty, think intent it's not option because on main menu. ideas how solve this? in advance ;)
Comments
Post a Comment