Здравствуйте, я получаю следующее исключение, и я не знаю, почему: Не удалось найти метод checkPassword (View) в классе активности android.view.ContextThemeWrapper для обработчика onClick в классе вида android. widget.Button с идентификатором 'bPassword'Исключение метода onlick-метода Android
Я использую диалог Activtiy как Dialog. Пользователь должен ввести пароль в диалоговом окне, если он правильный, нужно вызвать другое действие. Вот мой код:
Мой XML-файл:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Enter your Password:"
android:id="@+id/dText"/>
<EditText
android:layout_width="match_parent"
android:paddingLeft="10dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/ePassword"
android:layout_marginLeft="-1dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/bPassword"
android:onClick="checkPassword" />
</LinearLayout>
Мои Java Класс:
package com.example.RemindMe;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class DialogActivity extends Activity {
private String password = "test";
private EditText ePassword;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.activity_dialog);
dialog.setTitle("Note Activity is password protected");
dialog.setCancelable(true);
textView = (TextView) dialog.findViewById(R.id.dText);
textView.setText("Message");
dialog.show();
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
public void onCancel(DialogInterface arg0){
finish();
}
});
}
public void checkPassword(View view){
switch (view.getId()){
case R.id.bPassword:
String pwEditText = ePassword.getText().toString();
if(pwEditText.equals(password)){
//If password correct, start another activity
startActivity (new Intent(getApplicationContext(), NoteActivity.class));
} else {
textView.setText("Wrong Password, PLS Type it again");
}
break;
}
}
}
Я знаю, что пароль не должен использоваться в качестве четкого текста и так далее. Это только для целей тестирования. Я планирую использовать хэш и хранить пароль в sharedpref
thx, ваше решение отлично работает. Также thx всем остальным за помощью – androidBeginner