Juliatzin
Juliatzin

Reputation: 19695

change action bar icon as a response of dialogfragment

In my activiy, I open a DialogFragment to insert data in db. When I'm done, i dismiss the dialog, but I would like to change the sync icon of the activity to a red sync icon ( to say the user there is data to sync). The only way I can do is just before I dismiss, call a public method that belongs to the activity from the dialog, but I can't reach the Menu Items How can I do???

Upvotes: 1

Views: 249

Answers (1)

Juliatzin
Juliatzin

Reputation: 19695

When I close the dialog, I call a method that invoke from the DialogFragment:

invalidateOptionsMenu();

then, it enters in the onPrepare Method :

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem menuSync= menu.findItem(R.id.menu_sync);
    int sincronizado = prefs.getInt("sincronizado", 0);
   if (sincronizado == 1)
       menuSync.setIcon(R.drawable.ic_action_update_red);
    return super.onPrepareOptionsMenu(menu);
}

Upvotes: 1

Related Questions