I’m new to Android. I need to start a new intent activity based on if condition, but
the if condition is not working, but the value gets printed in the log file.
the code that I use is given below:
package com.example.helloandroid;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton next2 = (ImageButton)findViewById(R.id.imageButton1);
next2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText pin =(EditText)findViewById(R.id.editText1); //value from edit text
Log.v("EditText", pin.getText().toString()); //this works in log
if (pin.equals(0000)){
Intent myIntent = new Intent(view.getContext(), home.class);
startActivityForResult(myIntent, 1);
}
}
});
}
@Override
public void onBackPressed() {
return;
}
}
You’re comparing
pinwhich is theEditTextand not the string to0000which is not a string either. You want: