I have an item in my menu
case R.id.theme:
ShowRadioDialog();
return true;
With a method that shows an Alert dialog with 3 radio buttons. When i click the item the dialog shows but when i choose some item inside the dialog and i tap in the positiove buttons nothing happens. This is the method:
public void ShowRadioDialog() {
final CharSequence[] items={"Rosso","Verde","Blu"};
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setTitle("Seleziona un colore");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(DialogInterface dialog, int which) {
if (wich== 1) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(MainActivity.this.getResources().getColor(R.color.red));
toolbar.setBackgroundColor(MainActivity.this.getResources().getColor(R.color.red));
Toast.makeText(MainActivity.this, "Rosso OK", Toast.LENGTH_SHORT).show();
Log.i("Colors", "Rosso Ok");
}
} else if (wich ==2) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(MainActivity.this.getResources().getColor(R.color.green_welcome));
}
} else if (wich == 3){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(MainActivity.this.getResources().getColor(R.color.primary_dark_blue));
}
}
}
});
builder.setSingleChoiceItems(items,-1, new DialogInterface.OnClickListener() {
@SuppressLint("NewApi")
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if ("Rosso".equals(items[which])) {
which = 1;
} else if ("Verde".equals(items[which])) {
which = 2;
} else if ("Blu".equals(items[which])) {
which = 3;
}
}
});
builder.show();
}
I'm not sure it's the correct way. However, not either one (log in the logcat and the Toast in the application) appears. Seems that the positive button not accept the choice. Something is wrong?