1
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是真的還是錯的,什麼這個程序的問題,請告訴我回答...如果按鈕點擊收聽的Android條件錯誤
謝謝先生......幫助我很好的答案.. – Alamgir