public class MainActivity extends Activity {
EditText t1,t2;
TextView v1,v2;
String username1 = "admin";
String password1 = "12345";
Button b1;
String user;
Context c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
c = getApplicationContext();
t1 = (EditText) findViewById(R.id.editText1);
t2 = (EditText) findViewById(R.id.editText2);
b1 = (Button) findViewById(R.id.button1);
v1 = (TextView) findViewById(R.id.textView1);
v2 = (TextView) findViewById(R.id.textView2);
v1.setTextColor(Color.WHITE);
v2.setTextColor(Color.WHITE);
button();
}
public void button()
{
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
user = t1.getText().toString();
String pass = t2.getText().toString();
if(user == username1 && pass == password1)
{
Intent aa = new Intent(MainActivity.this, admin.class);
startActivity(aa);
}
else
{
Toast.makeText(c, "username or password is incorrect",Toast.LENGTH_LONG).show();
}
}
});
}
}
每次 else 块都会执行,如果 codition 是对还是错,这个程序有什么问题,请告诉我答案...