mercredi 27 mai 2015

Get an item apearing twice in the menu, but only one defined in res/menu/ xml file

I set-up a list of items for the MainActivity. Today only one item this menu.

<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://ift.tt/nIICcg"
    xmlns:app="http://ift.tt/GEGVYd"
    xmlns:tools="http://ift.tt/LrGmb4"
    tools:context="fr.vincelec.sunshine.sunshine.app.ForecastFragment">

<item android:id="@+id/action_refresh"
android:title="@string/refresh"
app:showAsAction="never"/>

</menu>

Also Here is the code to enable the menu:

 @Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
    inflater.inflate(R.menu.forecastfragment, menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
    int id = item.getItemId();
    if (id == R.id.action_refresh) {
        FetchWeatherTask weatherTask = new FetchWeatherTask();
        weatherTask.execute();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

But when I launch the program in my Android phone, and click on the menu, I see twice the item "Refresh", not only one item ...

I checked if there is something in MainActivity.java or main.xml but without success, It's only on my fragment file "ForecastFragment.java" (where the piece of code shown before is from) that I call the R.menu.forecastfragment .

Thanks a lot for your help :-)

Aucun commentaire:

Enregistrer un commentaire