Is there a android-standard badge or method to show action-bar notification icon with a count from android Fragment Button Click -


enter image description here

i wants update count notification fragment's button onclick event

for m doing that: uses custom button show count badger:

please tell me if know need changed in case, have button.

custom item on menu - menumain.xml

 <item      android:id="@+id/badge"      android:actionlayout="@layout/feed_update_count"      android:icon="@drawable/shape_notification"      android:showasaction="always">  </item> 

custom shape drawable (background square) - shape_notification.xml

 <?xml version="1.0" encoding="utf-8"?>  <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle">     <stroke android:color="#22000000" android:width="2dp"/>     <corners android:radius="5dp" />     <solid android:color="#cc0001"/> </shape> 

layout view - feed_update_count.xml

 <?xml version="1.0" encoding="utf-8"?>  <button xmlns:android="http://schemas.android.com/apk/res/android"      android:id="@+id/notif_count"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:minwidth="32dp"      android:minheight="32dp"       android:background="@drawable/shape_notification"      android:text="0"      android:textsize="16sp"      android:textcolor="@android:color/white"      android:gravity="center"      android:padding="2dp"      android:singleline="true">     </button> 

my fragment:

    private onaddproductlistener callback;     public int count = 0;    @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         sethasoptionsmenu(true);         if (getarguments() != null) {             mparam1 = getarguments().getstring(arg_param1);             mparam2 = getarguments().getstring(arg_param2);         }       }  @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) {     // todo add menu entries here     super.oncreateoptionsmenu(menu, inflater); }  @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     // inflate layout fragment     return inflater.inflate(r.layout.fragment_product_detail, container, false); }  @override public void onviewcreated(view view, bundle savedinstancestate) {     super.onviewcreated(view, savedinstancestate);      cartview = (view)v.findviewbyid(r.id.cartview);     buynow = (view)v.findviewbyid(r.id.buyview);      cartview.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {              toast.maketext(getactivity(),"added cart", toast.length_short).show();       //      myfragment = cartfragment.newinstance("", "");       //      activityutils.launchfragementwithanimation(myfragment, getactivity());              int count = 5;             callback.onproductadd(count);         }     }); }  public interface onaddproductlistener {     public void onproductadd(int params); } 

mainactivity:

  static button cartcount;   static int mcartcount = 0;     @override public boolean oncreateoptionsmenu(menu menu) {     getmenuinflater().inflate(r.menu.menu_main, menu);      view count = menu.finditem(r.id.action_cart).getactionview();     cartcount = (button) count.findviewbyid(r.id.cart_count);     cartcount.settext(string.valueof(mcartcount));     return super.oncreateoptionsmenu(menu); }  @override public boolean onoptionsitemselected(menuitem item) {     int id = item.getitemid();      switch (id) {         case android.r.id.home:             fragmentmanager fm = getfragmentmanager();             if (fm.getbackstackentrycount() > 1) {                 if (drawertoggle.onoptionsitemselected(item))                     return true;             } else if (fm.getbackstackentrycount() == 1) {                 if (drawertoggle.onoptionsitemselected(item))                     return true;             } else if (fm.getbackstackentrycount() == 0) {                 if (drawertoggle.onoptionsitemselected(item))                     return true;             }             return true;          case r.id.action_cart:             myfragment = cartfragment.newinstance("", "");             activityutils.launchfragementwithanimation(myfragment, mainactivity.this);             return true;         default:             return super.onoptionsitemselected(item);     } }   @override public void onproductadd(int params) {     mcartcount = params;     invalidateoptionsmenu(); } 

please tell me how can achieve task doing mistake.

give call mainactivity , using interface , extend interface in mainactivity call method on click


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -