android - Google Maps V2 + Drawer Layout -


i have tried add drawer layout(from android tutorial) "hello world" google maps app. problem cannot click items on sliding menu. think there's issue fragment part in xml. i've tried find workaround none worked. ideas how add in different way make work?

here's activity code:

public class mainactivity extends fragmentactivity { private googlemap mmap; private supportmapfragment fragment; private drawerlayout mdrawerlayout; private listview mdrawerlist; private actionbardrawertoggle mdrawertoggle;  private charsequence mdrawertitle; private charsequence mtitle; private string[] mplanettitles;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     requestwindowfeature(window.feature_action_bar);     setcontentview(r.layout.activity_main);     setupmapifneeded();     mtitle = mdrawertitle = gettitle();     mplanettitles = getresources().getstringarray(r.array.menu_item);     mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout);     mdrawerlist = (listview) findviewbyid(r.id.left_drawer);      // set custom shadow overlays main content when drawer opens     mdrawerlayout.setdrawershadow(r.drawable.drawer_shadow, gravitycompat.start);     mdrawerlist.setadapter(new arrayadapter<string>(this,             r.layout.draw_item, mplanettitles));     // set drawer's list view items , click listener     mdrawerlist.setonitemclicklistener(new draweritemclicklistener());      // enable actionbar app icon behave action toggle nav drawer     getactionbar().setdisplayhomeasupenabled(true);     getactionbar().sethomebuttonenabled(true);      // actionbardrawertoggle ties the proper interactions     // between sliding drawer , action bar app icon     mdrawertoggle = new actionbardrawertoggle(             this,                  /* host activity */             mdrawerlayout,         /* drawerlayout object */             r.drawable.ic_drawer,  /* nav drawer image replace 'up' caret */             r.string.drawer_open,  /* "open drawer" description accessibility */             r.string.drawer_close  /* "close drawer" description accessibility */             ) {         /** called when drawer has settled in closed state. */         public void ondrawerclosed(view view) {             super.ondrawerclosed(view);          }          /** called when drawer has settled in open state. */         public void ondraweropened(view drawerview) {             super.ondraweropened(drawerview);          }      };     mdrawerlayout.setdrawerlistener(mdrawertoggle);      if (savedinstancestate == null) {         selectitem(0);     } }  @override protected void onresume() {     super.onresume();     setupmapifneeded(); }  private void setupmapifneeded() {     if (mmap != null) {         return;     }     mmap = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map)).getmap();     if (mmap == null) {         return;     }     // initialize map options. example:     // mmap.setmaptype(googlemap.map_type_hybrid);     mmap.setmylocationenabled(true);     mmap.setonmapclicklistener(new googlemap.onmapclicklistener() {         @override         public void onmapclick(latlng point) {              markeroptions marker = new markeroptions().position(                     new latlng(point.latitude, point.longitude)).title("new marker");              mmap.addmarker(marker);          //system.out.println(point.latitude+"---"+ point.longitude);           }     });      //mmap.setonmarkerclicklistener((onmarkerclicklistener) this); }  /* @override public boolean oncreateoptionsmenu(menu menu) {     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.main, menu);     return super.oncreateoptionsmenu(menu); } */  /* called whenever call invalidateoptionsmenu() */ @override public boolean onprepareoptionsmenu(menu menu) {     // if nav drawer open, hide action items related content view     boolean draweropen = mdrawerlayout.isdraweropen(mdrawerlist);     return super.onprepareoptionsmenu(menu); }  @override public boolean onoptionsitemselected(menuitem item) {     // pass event actionbardrawertoggle, if returns     // true, has handled app icon touch event     if (mdrawertoggle.onoptionsitemselected(item)) {       return true;     }     // handle other action bar items...      return super.onoptionsitemselected(item); }   /* click listner listview in navigation drawer */ private class draweritemclicklistener implements listview.onitemclicklistener {     @override     public void onitemclick(adapterview<?> parent, view view, int position, long id) {         selectitem(position);     } }  private void selectitem(int position) {     // update main content replacing fragments     // update selected item , title, close drawer     mdrawerlist.setitemchecked(position, true);     mdrawerlayout.closedrawer(mdrawerlist); }   @override protected void onpostcreate(bundle savedinstancestate) {     super.onpostcreate(savedinstancestate);     // sync toggle state after onrestoreinstancestate has occurred.     mdrawertoggle.syncstate(); }  @override public void onconfigurationchanged(configuration newconfig) {     super.onconfigurationchanged(newconfig);     // pass configuration change drawer toggls     mdrawertoggle.onconfigurationchanged(newconfig); }  } 

and xml:

 <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">  <!-- main content view -->  <framelayout     android:id="@+id/content_frame"     android:layout_width="match_parent"     android:layout_height="match_parent" /> <!-- navigation drawer -->  <listview android:id="@+id/left_drawer"     android:layout_width="240dp"     android:layout_height="match_parent"     android:layout_gravity="start"     android:choicemode="singlechoice"     android:divider="@android:color/transparent"     android:dividerheight="0dp"     android:background="#111"/>  <fragment xmlns:android="http://schemas.android.com/apk/res/android"       xmlns:map="http://schemas.android.com/apk/res-auto"       android:id="@+id/map"       android:layout_width="match_parent"       android:layout_height="match_parent"       android:name="com.google.android.gms.maps.supportmapfragment"       map:maptype="normal"/>  </android.support.v4.widget.drawerlayout>     

draw_item layout:

<textview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelistitemsmall" android:gravity="center_vertical" android:paddingleft="16dp" android:paddingright="16dp" android:textcolor="#fff" android:background="?android:attr/activatedbackgroundindicator" android:minheight="?android:attr/listpreferreditemheightsmall"/> 

see below solution.

the problem order of items in main_activity.xml. here code makes work:

<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"> <!-- main content view --> <framelayout     android:id="@+id/content_frame"     android:layout_width="match_parent"     android:layout_height="match_parent"      /> <!-- navigation drawer -->  <fragment xmlns:android="http://schemas.android.com/apk/res/android"       xmlns:map="http://schemas.android.com/apk/res-auto"       android:id="@+id/map"       android:layout_width="match_parent"       android:layout_height="match_parent"       android:name="com.google.android.gms.maps.supportmapfragment"       map:maptype="normal"/>  <listview android:id="@+id/left_drawer"     android:layout_width="240dp"     android:layout_height="match_parent"     android:layout_gravity="start"     android:choicemode="singlechoice"     android:divider="@android:color/transparent"     android:dividerheight="0dp"     android:background="#111"/> 


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -