i have refresh icon on menu when clicked refresh contents of activity. problem refresh icon still clickable while refreshing not want. here menu.xml 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_refresh" android:orderincategory="100" android:icon="@mipmap/ic_refresh" android:enabled="true" android:title="@string/action_settings" app:showasaction="always"/>
and here handle click event icon
@override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if (id == r.id.action_refresh) { // getdata() fetches data , updates display getdata(); return true; } return super.onoptionsitemselected(item); }
also, there way maybe dim icon user knows have clicked icon?
when click icon, use isenabled()
method of menuitem check if enabled. if is, disable until data loaded. once data loads successfully, can enable again. example:
@override public boolean onoptionsitemselected(menuitem item) { int id = item.getitemid(); if(item.isenabled()) { // "dim" icon said. can use other alpha values if like. item.geticon().setalpha(130); // disable menu icon item.setenabled(false); } getdata(); return true; } return super.onoptionsitemselected(item); }
now, said have getdata()
method updates display after fetches data. once data fetched, check if menuitem
disabled. if disabled, enable again. example:
if(item != null && item.isenabled() == false) { // "undim" icon item.geticon().setalpha(255); // enable again item.setenabled(true); }
Comments
Post a Comment