I'm doing a switch case into onOptionsItemSelected
, and i want to assign a title value for this item, but it don't works.
The problem apears in the case R.id.numTaula
, when I use menu.Android says:
Qualifier must be an expresion.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
case R.id.carrito:
carrito c = new carrito();
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.replace(R.id.frame_container, c);
ft.commit();
return true;
case R.id.alerta:
AlertDialog.Builder cambrer = new AlertDialog.Builder(this);
cambrer.setTitle("Demanar cambrer");
cambrer.setMessage("Està seguir que desitja l'atenció del cambrer?");
cambrer.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
alertaCambrer = true;
}
});
cambrer.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
alertaCambrer = false;
}
});
cambrer.show();
break;
case R.id.numTaula:
AlertDialog.Builder AlertTaula = new AlertDialog.Builder(this);
AlertTaula.setTitle("Numero de taula");
AlertTaula.setMessage("Introdueix el numero de taula");
// Set an EditText view to get user input
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setRawInputType(Configuration.KEYBOARD_12KEY);
AlertTaula.setView(input);
AlertTaula.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
numTaula = input.getText().toString();
menu.findItem(R.id.numTaula).setTitle(numTaula);
}
});
AlertTaula.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
AlertTaula.show();
break;
default:
return super.onOptionsItemSelected(item);
}return super.onOptionsItemSelected(item);
}