0
Android 용 잠금 화면 앱을 만들고 있지만 정확한 비밀번호를 입력하면 활동이 완료되지 않는 문제가 있습니다. 코드 작업은 암호가 하나의 문자 인 경우에만 작동합니다. 그렇지 않으면 잠금 해제되지 않습니다. 전역 변수를 수정하는 방법과 관련이 있다고 생각합니다.Android 맞춤 화면 잠금 비밀번호
테스트 할 때 사용하는 코드입니다. 두 텍스트 뷰를 순서대로 터치하여 잠금을 해제해야하지만 그렇지 않습니다.
public class LockScreen extends Activity implements OnClickListener {
String password = "cd";
String guess;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lock_layout);
TextView c = (TextView) findViewById(R.id.c);
TextView d = (TextView) findViewById(R.id.d);
c.setOnClickListener(this);
d.setOnClickListener(this);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.c:
if (guess == null) {
guess = "c";
} else {
guess += "c";
}
break;
case R.id.d:
if (guess == null) {
guess = "d";
} else {
guess += "d";
}
break;
}
if (guess == password) {
finish();
}
}