0
I’m trying to create two buttons but it’s only working when I click one of the buttons.
My Activity is as follows:
<?xml version="1.0" encoding="utf-8"?>
<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" >
<item
android:id="@+id/comentar"
android:icon="@drawable/comentarios"
android:title="Verificar todos comentarios do estabelecimento"
app:showAsAction="ifRoom" />
<item
android:id="@+id/favoritar"
android:icon="@drawable/ic_favoritar"
android:title="Adicionar estabelecimento aos favoritos"
app:showAsAction="ifRoom"/>
</menu>
Already in my class like this:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_favoritar_restaurante, menu);
menuItemCoracao = menu.getItem(0);
if (restaurante.isFavorito()) {
// Altera o icone para favoritado
menuItemCoracao.setIcon(R.drawable.ic_favoritado);
}
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (!restaurante.isFavorito()) {
// Adiciona aos favoritos
adicionarAosFavoritos();
} else {
// Remove
removerDosFavoritos();
}
return super.onOptionsItemSelected(item);
}
The logic of the first is working perfectly, but now I need to create the logic of the second, where I will send to a new java that will do the comments search of that respective client.
How to do this ? Where am I going wrong ?
The problem is that now you’re changing the wrong icon
– Renan Rodrigues
no item onCreateOptionsMenu
– Renan Rodrigues
Try putting 1 instead of 0 on
menu.getItem(0);
– Leonardo Dias
I did it here and it worked
– Renan Rodrigues
vlw, Aja accept your answer
– Renan Rodrigues