android - Counter on toolbar cart icon -


i trying add counter on cart icon

public boolean oncreateoptionsmenu(final menu menu) {         if (!mnavigationdrawerfragment.isdraweropen()) {             menu.clear();             getmenuinflater().inflate(r.menu.main, menu);             relativelayout badge =(relativelayout)menu.finditem(r.id.action_cart).getactionview();             ui_hot = (textview) badge.findviewbyid(r.id.count);         }  return super.oncreateoptionsmenu(menu); } 

but following message:

java.lang.nullpointerexception: attempt invoke virtual method 'android.view.view android.widget.relativelayout.findviewbyid(int)' on null object reference 

following xml menu file:

<menu xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     tools:context=".mainactivity">      <item         android:id="@+id/action_cart"         android:title="test counter action"         android:orderincategory="1"         android:actionlayout="@layout/cart_update_count"         app:showasaction="always" />  </menu> 

this may out`

<android.support.v7.widget.toolbar     android:id="@+id/toolbar"     android:layout_width="match_parent"     android:layout_height="?attr/actionbarsize"     android:background="?attr/colorprimary"     android:theme="@style/themeoverlay.appcompat.dark.actionbar"     app:popuptheme="@style/themeoverlay.appcompat.light">       <textview          android:layout_width="match_parent"          android:layout_height="match_parent"          android:id="@+id/mytextview"          android:background="#000000" /> </android.support.v7.widget.toolbar>`** 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -