I'm trying to create two buttons but it's only working when I click on one of the buttons.
Myactivitylookslikethis:
<?xmlversion="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 it looks 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 one is working perfectly, but now I need to create the logic of the second one, where I will send it to a new java that will search the comments of that respective client.
How to do this? Where am I going wrong?