我創建了一個screen要求密碼和內置的密碼比較,啟動另一個屏幕,但是我輸入正確的密碼也還是無法啟動activity。如何解決這個問題呢?
public class MainActivity extends Activity {
public static String lock = "vamsi";
public static String locker;
EditText et;
Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = (EditText) findViewById(R.id.editText1);
b = (Button) findViewById(R.id.button1);
locker = et.getText().toString();
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
if (locker.equals(lock)) {
Intent intent = new Intent("screen");
startActivity(intent);
}
}
});
}
}
用 Intent intent = new Intent (getApplicationContext(), FileName.class);
代替 Intent intent = new Intent("screen");
,這裡的 FileName 是 Onclick Method 方法中你要打開的 activity 的名稱。