Hi Im new to android development and this is my first post on stackoverFlow. I am trying to make an in which there is a picture of say brad pitt a edit text and a button. the object is to guess who is in the picture. i want it so that if the user types in brad pitt and clicks the button it will bring them onto the second page with a different picture and if incorrect it could do a toast "Wrong Answer". My problem is that it wont go to the second page when given the right answer.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button submit = (Button) findViewById(R.id.button1);
EditText input = (EditText) findViewById(R.id.etAnswer);
final String userinput = input.toString();
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
{if (userinput.equals("tom")) {
Intent myintent = new Intent (MainActivity.this,MainActivity2.class) ;
startActivity (myintent);
;
}else{
Toast.makeText(getApplicationContext(), "Wrong Answer", Toast.LENGTH_SHORT ).show();
}
}
}});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}