【发布时间】:2014-01-22 19:20:35
【问题描述】:
我对 JAVA 和 android 开发非常陌生,正在尝试使用密码保护我的应用程序。 我试图做到这一点,以便每当用户按下提交按钮时,如果密码正确,它将开始一个新的活动。
到目前为止,我有以下代码:
对于我的按钮:
<Button
android:id="@+id/button_enterpassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_enterpassword"
android:layout_centerHorizontal="true"
android:layout_marginTop="262dp"
android:onClick="openMenu"
android:textSize="60sp"
android:text="@string/button_confirm"
/>
对于我的活动:
// This is the method called when the user presses the button
public void openMenu(View view) {
MyMethods compareText = new MyMethods();
boolean same = compareText.compareText();
if(same = true){
MyMethods openActivity = new MyMethods();
openActivity.callActivity();
}
}}
对于我的 MyMethods 类:
public class MyMethods extends Activity {
public void callActivity() {
Intent intent = new Intent(this , MainMenu.class);
startActivity(intent);
}
public boolean compareText() {
boolean same = false;
//assigning the name sumbitButton to the button from the UI
//Button sumbitButton = (Button) findViewById(R.id.button_enterpassword);
//Defines when the user has selected the button
// sumbitButton.setOnClickListener(new View.OnClickListener() {
//public void onClick(View v){
//assigning the name passwordEditText to the text inside the textbox
EditText passwordEditText = (EditText)
findViewById(R.id.text_enterpassword);
if(passwordEditText.getText().toString().equals("Test")){
same = true;
}
return same;
}
}
但是,每当我按下按钮时,我的程序就会崩溃。
为您的帮助干杯!
【问题讨论】:
-
您应该发布错误堆栈跟踪以获得更好的答案。
标签: android button crash passwords