android - onSetItemClickListener not working -


hey saw many solutions none pertain me... using actionbaractivity toolbar , cannot mdrawerlist.setonitemclicklistener(new adapterview.onitemclicklistener() {

this code:

     mtoolbar = (toolbar) findviewbyid(r.id.toolbar);         mdrawerlist = (listview)findviewbyid(r.id.navlist);         mdrawerlayout = (drawerlayout)findviewbyid(r.id.drawer_layout);         mactivitytitle = gettitle().tostring();         setsupportactionbar(mtoolbar);         adddraweritems();         setupdrawer();         getsupportactionbar().setdisplayhomeasupenabled(true);         getsupportactionbar().sethomebuttonenabled(true);  public void adddraweritems() { log.d(constants.debug, "adding drawer items");         draweradapter = new draweradapter(this);         mdrawerlist.setadapter(draweradapter);          mdrawerlist.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                  log.d(constants.debug, "drawer items clicked");                 toast.maketext(mainactivity.this, "time upgrade!", toast.length_short).show();                 if(position == 2) {                     takeusertoprofile();                 }             }         });   }   public class draweradapter extends baseadapter {     private context mcontext;     private arraylist<string> draweritems;      public draweradapter(context c) {         mcontext = c;         draweritems = setupitems();      }      private arraylist<string> setupitems() {         arraylist<string> draweritemnames = new arraylist<string>();          draweritemnames.add("search");         draweritemnames.add("home");         draweritemnames.add("profile");         draweritemnames.add("share");         draweritemnames.add("logout");          return draweritemnames;     }      @override     public int getcount() {         return 5;     }      @override     public object getitem(int position) {         return position;     }      @override     public long getitemid(int position) {         return position;     }      @override     public view getview(final int position, view convertview, viewgroup parent) {         view v = convertview;         if (v == null) {             layoutinflater inflater = (layoutinflater) mcontext                     .getsystemservice(context.layout_inflater_service);              v = inflater.inflate(r.layout.drawer_item, null);         }          textview draweritem = (textview) v.findviewbyid(r.id.draweritem);         draweritem.settext(draweritems.get(position));          return v;     }  } 

this xml:

<android.support.v4.widget.drawerlayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/drawer_layout"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <!-- first child in layout main activity ui-->     <relativelayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:paddingleft="@dimen/activity_horizontal_margin"         android:paddingright="@dimen/activity_horizontal_margin"         android:paddingtop="@dimen/activity_vertical_margin"         android:paddingbottom="@dimen/activity_vertical_margin"         tools:context=".mainactivity"         android:background="#ffffffff">          <textview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerhorizontal="true"             android:text="holy operating systems, batdroid!"             android:textsize="24sp"             android:gravity="center"             android:layout_margintop="100dp"/>          <imageview             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:src="@drawable/ic_launcher"             android:layout_alignparentbottom="true"             android:layout_centerhorizontal="true"/>      </relativelayout>      <android.support.v7.widget.toolbar         xmlns:android="http://schemas.android.com/apk/res/android"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/toolbar"         android:background="?attr/colorprimarydark">         <textview android:text="u titel"             android:textappearance="@android:style/textappearance.theme"             android:textcolor="@android:color/holo_red_dark"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />     </android.support.v7.widget.toolbar>      <!-- side navigation drawer ui -->     <listview         android:id="@+id/navlist"         android:layout_width="200dp"         android:layout_height="match_parent"         android:layout_gravity="left|start"         android:background="@android:color/holo_red_dark"/>       <relativelayout         xmlns:app="http://schemas.android.com/apk/res-auto"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:paddingleft="@dimen/activity_horizontal_margin"         android:paddingright="@dimen/activity_horizontal_margin"         android:paddingtop="@dimen/activity_vertical_margin"         android:paddingbottom="@dimen/activity_vertical_margin"         tools:context=".mainactivity"         android:id="@+id/mainparentlayout"         android:gravity="center">          <com.alamkanak.weekview.weekview             android:id="@+id/weekview"             android:layout_width="match_parent"             android:layout_height="match_parent"             app:eventtextcolor="@android:color/white"             app:textsize="12sp"             app:hourheight="60dp"             app:headercolumnpadding="8dp"             app:headercolumntextcolor="#8f000000"             app:headerrowpadding="12dp"             app:columngap="8dp"             app:noofvisibledays="3"             app:headerrowbackgroundcolor="#ffefefef"             app:daybackgroundcolor="#05000000"             app:todaybackgroundcolor="#1848adff"             app:headercolumnbackground="#ffffffff"             android:layout_above="@+id/updatebuttonlayout"/>          <linearlayout             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:orientation="vertical"             android:layout_alignparentbottom="true"             android:id="@+id/updatebuttonlayout"></linearlayout>      </relativelayout>  </android.support.v4.widget.drawerlayout> 

this adapter list item xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical" android:layout_width="match_parent"     android:layout_height="match_parent">     <textview         android:layout_width="wrap_content"         android:layout_height="50dp"         android:layout_marginleft="15dp"         android:textcolor="@android:color/background_dark"         android:id="@+id/draweritem"         />      <view android:id="@+id/separator"         android:background="#222222"         android:layout_width = "fill_parent"         android:layout_height="1dip"         android:layout_centervertical ="true"         android:layout_below="@+id/draweritem"/> </linearlayout> 

you can implement in adapter class this

 draweritem.setonclicklistner(new onclicklistner(){         public void onclick(view v) {          log.d(constants.debug, "drawer items clicked");                 toast.maketext(mcontext, "time upgrade!", toast.length_short).show();  integer position = (integer) v.gettag();                 if(position == 2) {                     takeusertoprofile();                 } } }); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -