android - onitemclick() of listview not working in navigation drawer -


i building navigation drawer in when 1 item clicked opens new activity in musicplayer. problem listview created , items listed in it. on itemclick nothing happens. below's code:

    @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.audioedit);     mtitle = mdrawertitle = gettitle();      // load slide menu items     navmenutitles = getresources().getstringarray(r.array.nav_drawer_items);      // nav drawer icons resources     navmenuicons = getresources()             .obtaintypedarray(r.array.nav_drawer_icons);      mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout);     mdrawerlist = (listview) findviewbyid(r.id.list_slidermenu);      navdraweritems = new arraylist<navdraweritem>();      // adding nav drawer items array     // home     navdraweritems.add(new navdraweritem(navmenutitles[0], navmenuicons.getresourceid(0, -1)));     // find people     navdraweritems.add(new navdraweritem(navmenutitles[1], navmenuicons.getresourceid(1, -1)));       // recycle typed array     navmenuicons.recycle();     log.d("navicon", "recycle");      mdrawerlist.setonitemclicklistener(new onitemclicklistener() {          @override         public void onitemclick(adapterview<?> arg0, view arg1, int position,                 long arg3) {             // display view selected nav drawer item             displayview(position);             log.d("onslidermenu", string.valueof(position));          }     });     log.d("drawerclicklistener", "set");       /* nadapter = new arrayadapter<string>(                 getapplicationcontext(),                 r.layout.drawer_list_item ,                 navmenutitles);      */      // setting nav drawer list adapter     adapter = new navdrawerlistadapter(getapplicationcontext(),             navdraweritems);     mdrawerlist.setadapter(adapter);      // enabling action bar app icon , behaving toggle button     getactionbar().setdisplayhomeasupenabled(true);     //getactionbar().sethomebuttonenabled(true);      mdrawertoggle = new actionbardrawertoggle(this, mdrawerlayout,             r.drawable.ic_drawer, //nav menu toggle icon             r.string.app_name, // nav drawer open - description accessibility             r.string.app_name // nav drawer close - description accessibility     ) {         public void ondrawerclosed(view view) {              mdrawerlayout.closedrawer(mdrawerlist);             getactionbar().settitle(mtitle);             // calling onprepareoptionsmenu() show action bar icons             invalidateoptionsmenu();         }          public void ondraweropened(view drawerview) {             mdrawerlayout.opendrawer(mdrawerlist);             getactionbar().settitle(mdrawertitle);             // calling onprepareoptionsmenu() hide action bar icons             invalidateoptionsmenu();         }     };     mdrawerlayout.setdrawerlistener(mdrawertoggle);      if (savedinstancestate == null) {         // on first time display view first nav item         displayview(0);     }          /**  * diplaying fragment view selected nav drawer list item  * */  private void displayview(int position) {     // update main content replacing fragments     log.d("indisplayview", string.valueof(position));      //fragment fragment = null;     switch (position) {     case 0:         toast.maketext(getapplicationcontext(), "home", toast.length_long).show();         break;     case 1:         intent i=new intent(getapplicationcontext(), equalizer.class);         startactivityforresult(i, 103);         break;      default:         break;     }           // update selected item , title, close drawer          mdrawerlist.setitemchecked(position, true);         mdrawerlist.setselection(position);         settitle(navmenutitles[position]);         mdrawerlayout.closedrawer(mdrawerlist);   }  @suppresslint("newapi") @override public void settitle(charsequence title) {     mtitle = title;     getactionbar().settitle(mtitle); }  /**  * when using actionbardrawertoggle, must call during  * onpostcreate() , onconfigurationchanged()...  */  @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); }  @override     public boolean onoptionsitemselected(menuitem item) {      // toggle nav drawer on selecting action bar app icon/title         if (mdrawertoggle.onoptionsitemselected(item)) {             return true;         }         // handle action bar actions click         switch (item.getitemid()) {         case r.id.action_settings:             return true;             }         return super.onoptionsitemselected(item);         }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.audioedit, menu);     getmenuinflater().inflate(r.menu.equalizer1, menu);     getmenuinflater().inflate(r.menu.equalizer2, menu);     getmenuinflater().inflate(r.menu.bpm, menu);     getmenuinflater().inflate(r.menu.reverbandbassboost, menu);     return true; }   /* *  * called when invalidateoptionsmenu() triggered  */ @override public boolean onprepareoptionsmenu(menu menu) {     // if nav drawer opened, hide action items     boolean draweropen = mdrawerlayout.isdraweropen(mdrawerlist);      menu.finditem(r.id.action_settings).setvisible(!draweropen);      return super.onprepareoptionsmenu(menu); } 

i using music player. hence navigation drawer need open other activity equalizer , other effects. in advance help.

here's layout.:

    <android.support.v4.widget.drawerlayout       xmlns:android="http://schemas.android.com/apk/res/android"       android:id="@+id/drawer_layout"    android:background="#000000"        android:layout_width="match_parent"        android:layout_height="match_parent">      <framelayout       android:id="@+id/frame_container"       android:layout_width="match_parent"       android:layout_height="match_parent" />  <!-- listview display slider menu --> <listview     android:id="@+id/list_slidermenu"     android:layout_width="240dp"     android:layout_height="match_parent"     android:layout_gravity="start"     android:choicemode="singlechoice"     android:divider="@color/list_divider"     android:dividerheight="1dp"             android:listselector="@drawable/list_selector"     android:background="@color/list_background"/>   <listview     android:id="@+id/list_slidermenu2"     android:layout_width="240dp"     android:layout_height="match_parent"     android:layout_gravity="end"     android:choicemode="singlechoice"     android:divider="@color/list_divider"     android:dividerheight="1dp"             android:listselector="@drawable/list_selector"     android:background="@color/list_background"/>       <relativelayout android:id="@+id/mrelative" android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin">  <imageview     android:id="@+id/imageview1"     android:layout_width="150dp"     android:layout_height="20dp"     android:layout_above="@+id/btnplay1"     android:layout_aligntop="@+id/btnrec"     android:src="@drawable/ic_launcher" />     <imagebutton     android:id="@+id/btnplay1"     android:layout_width="30dp"     android:layout_height="30dp"     android:layout_alignbottom="@+id/btnplay2"     android:layout_alignleft="@+id/imageview1"     android:background="@null"     android:src="@drawable/btn_play" />  <button     android:id="@+id/btncue2"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/btncue1"     android:layout_aligntop="@+id/btnplay2"     android:layout_toleftof="@+id/btnplay2"     android:text="cue" />  <imagebutton     android:id="@+id/btnplay2"     android:layout_width="30dp"     android:layout_height="30dp"     android:layout_alignparentbottom="true"     android:layout_alignright="@+id/imageview2"     android:background="@null"     android:src="@drawable/btn_play" />  <button     android:id="@+id/btncue1"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_aligntop="@+id/btnplay1"     android:layout_torightof="@+id/btnplay1"     android:text="cue" />  <button     android:id="@+id/btncall1"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/btncue1"     android:layout_aligntop="@+id/btncue1"     android:layout_torightof="@+id/btncue1"     android:text="call" />  <button     android:id="@+id/btncall2"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/btncue2"     android:layout_aligntop="@+id/btncue2"     android:layout_toleftof="@+id/btncue2"     android:text="call" />  <imagebutton     android:id="@+id/btnplaylist2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/btnrec"     android:layout_toleftof="@+id/imageview2"     android:background="@null"     android:src="@drawable/btn_playlist" />  <imagebutton     android:id="@+id/btnplaylist1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/btnrec"     android:layout_torightof="@+id/imageview1"     android:background="@null"     android:src="@drawable/btn_playlist" />  <imageview     android:id="@+id/imageview2"     android:layout_width="150dp"     android:layout_height="20dp"     android:layout_alignbottom="@+id/imageview1"     android:layout_alignparentright="true"     android:layout_aligntop="@+id/btnrec"     android:layout_marginright="38dp"     android:src="@drawable/ic_launcher" />  <seekbar     android:id="@+id/seekbar2"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_above="@+id/imageview1"     android:layout_alignleft="@+id/imageview1" />  <seekbar     android:id="@+id/seekbar1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_above="@+id/seekbar2"     android:layout_alignleft="@+id/seekbar2" />  <imagebutton     android:id="@+id/btnrec"     android:layout_width="30dp"     android:layout_height="30dp"     android:layout_centervertical="true"     android:layout_marginright="30dp"     android:layout_toleftof="@+id/btnplaylist2"     android:background="@null"     android:src="@drawable/btn_record" /> 

navdrawerlistadapter class:

    public class navdrawerlistadapter extends baseadapter {  private context context; private arraylist<navdraweritem> navdraweritems;  public navdrawerlistadapter(context context, arraylist<navdraweritem> navdraweritems){     this.context = context;     this.navdraweritems = navdraweritems; }  @override public int getcount() {     return navdraweritems.size(); }  @override public object getitem(int position) {            return navdraweritems.get(position); }  @override public long getitemid(int position) {     return position; }  @override public view getview(int position, view convertview, viewgroup parent) {     if (convertview == null) {         layoutinflater minflater = (layoutinflater)                 context.getsystemservice(activity.layout_inflater_service);         convertview = minflater.inflate(r.layout.drawer_list_item, null);     }      imageview imgicon = (imageview) convertview.findviewbyid(r.id.icon);     textview txttitle = (textview) convertview.findviewbyid(r.id.title);     textview txtcount = (textview) convertview.findviewbyid(r.id.counter);      imgicon.setimageresource(navdraweritems.get(position).geticon());             txttitle.settext(navdraweritems.get(position).gettitle());      // displaying count     // check whether set visible or not     if(navdraweritems.get(position).getcountervisibility()){         txtcount.settext(navdraweritems.get(position).getcount());     }else{         // hide counter view         txtcount.setvisibility(view.gone);     }      return convertview; } 

}

navdraweritem class:

    public class navdraweritem {  private string title; private int icon; private string count = "0"; // boolean set visiblity of counter private boolean iscountervisible = false;  public navdraweritem(){}  public navdraweritem(string title, int icon){     this.title = title;     this.icon = icon; }  public navdraweritem(string title, int icon, boolean iscountervisible, string count){     this.title = title;     this.icon = icon;     this.iscountervisible = iscountervisible;     this.count = count; }  public string gettitle(){     return this.title; }  public int geticon(){     return this.icon; }  public string getcount(){     return this.count; }  public boolean getcountervisibility(){     return this.iscountervisible; }  public void settitle(string title){     this.title = title; }  public void seticon(int icon){     this.icon = icon; }  public void setcount(string count){     this.count = count; }  public void setcountervisibility(boolean iscountervisible){     this.iscountervisible = iscountervisible; } 

}

drawer_list_item.xml:

    <?xml version="1.0" encoding="utf-8"?>     <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="48dp"       android:background="@drawable/list_selector">  <imageview     android:id="@+id/icon"     android:layout_width="25dp"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_marginleft="12dp"     android:layout_marginright="12dp"     android:contentdescription="@string/desc_list_item_icon"     android:src="@drawable/ic_home"     android:layout_centervertical="true" />  <textview     android:id="@+id/title"     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:layout_torightof="@id/icon"     android:textcolor="@color/list_item_title"     android:gravity="center_vertical"     android:paddingright="40dp"/>  <textview android:id="@+id/counter"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:background="@drawable/counter_bg"     android:layout_alignparentright="true"     android:layout_centervertical="true"     android:layout_marginright="8dp"     android:textcolor="@color/counter_text_color"/> 


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -