Disable refresh icon on Menu while content is being refreshed

I have a refresh icon on my menu which when clicked will refresh the contents of the Activity. But the problem is that the refresh icon is still clickable while it is refreshing which I do not want. Here is my 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 is where I handle the click event for the icon

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_refresh) {
        // getData() fetches the data and updates the display
        getData();
        return true;
    }

    return super.onOptionsItemSelected(item);
}

Also, is there a way to maybe dim the icon so that the user knows that they have already clicked the icon?


Source: xml

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.