E
E
Evgenij_Popovich2013-04-10 13:21:44
Android
Evgenij_Popovich, 2013-04-10 13:21:44

Broken view of ActionBar after calling invalidateOptionsMenu, setSupportProgressBarVisibility and notifyDataSetChanged?

Noticed some unpleasant behavior in ActionbBar (ActionBarSherlock in particular). In the application, I use FEATURE_INDETERMINATE_PROGRESS which is shown when performing some actions. Also, when progress is shown, the action refresh should be hidden. To hide it, I have to call invalidateOptionsMenu, which, in turn, calls onPrepareOptionsMenu where I can already change the visibility

Override
public void onPrepareOptionsMenu(Menu menu)
{
    reinitMenu(menu);
    super.onPrepareOptionsMenu(menu);
}
 
protected void reinitMenu(Menu menu)
{
    menu.findItem(R.id.menu_refresh).setVisible(
        !getFActivity().isLoading());
}

When data is loaded via AsyncTask in the onPostExecute method, notifyDataSetChanged is called sequentially on the model bound to the ListView, setSupportProgressBarVisibility and invalidateOptionsMenu.
    Override
        protected void onPostExecute(Void result)
        {
            super.onPostExecute(result);
            for (int i = 0; i < 10; i++)
            {
                adapter.items.add(i);
            }
            adapter.notifyDataSetChanged();
            activity.stopLoading();
        }

    void stopLoading()
    {
        if (loaders.decrementAndGet() == 0)
        {
            setSupportProgressBarIndeterminateVisibility(false);
            invalidateOptionsMenu();
        }
    }

This code in many cases "breaks" the view of the ActionBar. Icons disappear, an empty space appears on the right instead of
them . ; then the ActionBar will look correct. But I suspect that this is not the only possible reason for such a "breakdown". Perhaps someone has come across a similar one and knows how to properly deal with this problem? Link to the source of the project that demonstrates the problem goo.gl/ZbMTU Managed to reproduce on the emulator version 2.1 and on a device with Android ICS 4.0.3 on board.
de25ca5b38084f0cfddcbbea7cf2c3db.png
19eeed97f2e4cb0574369dd210db28d4.png
1fe85c4cff4772ce84fea80c68815349.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question