I have the following part of my code:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.barra_superior, menu); // toolboard
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.search:
openSearch();
return true;
case R.id.add:
openAdd();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
I created a menu and by clicking the add button
It should be something like this:
private void openAdd() {
final Button buttonAdd = (Button) findViewById(R.id.add);
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), inserir_Llibre.class);
startActivityForResult(intent, 0);
}
});
}
But it does not work for me, I've only changed screens with buttons, and I see that the toolboard works differently and I do not know how to make it work.
Do you help me?
thanks!