Common Navigation Menu drawer In Android -
i need add navigation drawer menu in android application. application has many modules can't code each activity display navigation menu. decided put navigation menu code in base activity. each activity extends base activity. navigation drawer menu's working problem activity components not working. don't know happening. there changes needed? in advance.
baseactivity.java public class baseactivity extends actionbaractivity { relativelayout fulllayout; drawerlayout dlayout; @override public void setcontentview(int layoutresid) { fulllayout = (relativelayout) getlayoutinflater().inflate( r.layout.activity_base, null); framelayout framelayout = (framelayout) fulllayout .findviewbyid(r.id.content_frame); listview dlist = (listview) fulllayout.findviewbyid(r.id.left_drawer); dlayout = (drawerlayout) fulllayout.findviewbyid(r.id.drawer_layout); getlayoutinflater().inflate(layoutresid, framelayout, true); setcontentview(fulllayout); string[] menu = new string[] { "home", "android", "windows", "linux", "raspberry pi", "wordpress", "videos", "contact us" }; arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, menu); dlist.setadapter(adapter); dlist.setselector(android.r.color.holo_blue_dark); dlist.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view v, int position, long id) { dlayout.closedrawers(); } }); }};
activity_base.xml
<relativelayout xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="sas.mobi.lakshmi.main.baseactivity" > <framelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.v4.widget.drawerlayout android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <listview android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#fff" android:choicemode="singlechoice" android:divider="@android:color/transparent" android:dividerheight="0dp" /> </android.support.v4.widget.drawerlayout>
homeactivity.java
public class homeandsettingactivity extends baseactivity { private button btnaccount; private button btncollection; private button btnothers; private button btntempexit; private button btnexit; private adminds adminds; private admindo admindo; private financeds financeds; private partnerpaymentds paymentds; private googlecloudmessaging gcm; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_home_and_setting); initializecomponents(); btnaccount.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(getapplicationcontext(), accountreghomeactivity.class); startactivity(intent); finish(); } }); btncollection.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(getapplicationcontext(), collectionhomeactivity.class); startactivity(intent); finish(); } }); btnothers.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(getapplicationcontext(), othershomeactivity.class); startactivity(intent); finish(); } }); btntempexit.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { finish(); } }); btnexit.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { financeds = new financeds(getapplicationcontext()); boolean isups = financeds.closeactivecurrentfinances(); if (isups) { finish(); } } }); } /** * method initialize components */ private void initializecomponents() { btnaccount = (button) findviewbyid(r.id.btnaccount); btncollection = (button) findviewbyid(r.id.btncollection); btnothers = (button) findviewbyid(r.id.btnothers); btntempexit = (button) findviewbyid(r.id.btntempexit); btnexit = (button) findviewbyid(r.id.btnexit); }};
acitivity_home.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="vertical" > <button android:id="@+id/btnaccount" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="1dp" android:background="?android:attr/dividervertical" android:text="@string/btnaccount" android:textsize="14sp" /> <button android:id="@+id/btncollection" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="1dp" android:background="?android:attr/dividervertical" android:text="@string/btncollection" android:textsize="14sp" /> <button android:id="@+id/btnothers" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="1dp" android:background="?android:attr/dividervertical" android:text="@string/btnothers" android:textsize="14sp" /> <button android:id="@+id/btntempexit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="1dp" android:background="?android:attr/dividervertical" android:text="@string/btntempexit" android:textsize="14sp" /> <button android:id="@+id/btnexit" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="1dp" android:background="?android:attr/dividervertical" android:text="@string/btnexit" android:textsize="14sp" />
this home activity , common navigation drawer menu's showing properly, component inside home activity not working.but drawer components working.
change main xml way , load sidemenu side menu frame:
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="sas.mobi.lakshmi.main.baseactivity" > <framelayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> </relativelayout> <framelayout android:id="@+id/side_menu" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v4.widget.drawerlayout>
Comments
Post a Comment