When i try this code which reads what the user has clicked and compares it to the button name it only seems to work for one array rather then the 2nd one. If anybody can see why please help me
case R.id.new_button:
final CharSequence[] items = {"N", "E", "M", "G"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a difficulty");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if ("N".equals(items[0]))
{Intent intent = new Intent();
Intent i0 = new Intent(B.this, Test1.class);
startActivity(i0);}
else if ("M".equals(items[2]))
{Intent intent = new Intent();
Intent i2 = new Intent(Brain.this, Test2.class);
startActivity(i2);;}
}
}).show();
AlertDialog alert = builder.create();
edit oops sorry i saw the wrong thing let me re-check your code
As your code is now, you will never hit the second part of the if statement since “N” always equals items[0]. So the else will never be execute.
This should work: