コードに「クリア」と「ログイン」の2つのボタンがあります。問題は、ログインボタンをクリックできないことですが、クリアボタンは問題なく機能します。私の間違いはどこにありますか?
以下のコードはプロジェクト全体です
public MyScreen()
{
// Set the displayed title of the screen
Bitmap logo = Bitmap.getBitmapResource("icon.png");
bitField = new BitmapField(logo, Field.FIELD_HCENTER);
userField = new EditField("Username :", "");
passField = new PasswordEditField("Password :", "");
ddlDomain = new ObjectChoiceField("Domain :", new String[] {"Home", "Work"});
chkRemember = new CheckboxField("Remember Password", false);
btnClear = new ButtonField("Clear", ButtonField.CONSUME_CLICK);
btnLogIn = new ButtonField("Log In", ButtonField.CONSUME_CLICK);
add(bitField);
add(new SeparatorField());
add(new LabelField("Please enter your credentials:"));
add(userField);
add(passField);
add(ddlDomain);
add(chkRemember);
HorizontalFieldManager btnManager = new HorizontalFieldManager(Field.FIELD_RIGHT);
btnManager.add(btnClear);
btnManager.add(btnLogIn);
add(btnManager);
btnClear.setChangeListener(this);
}
public void fieldChanged(Field field, int context) {
if(field == btnClear){
clearTextFields();
}
else if(field == btnLogIn){
login();
}
}
private void clearTextFields(){
userField.setText("");
passField.setText("");
}
private void login(){
if(userField.getTextLength() == 0 || passField.getTextLength() == 0){
Dialog.alert("You must enter a username and password");
}
else{
String username = userField.getText();
String selectedDomain = (String)ddlDomain.getChoice(ddlDomain.getSelectedIndex());
SuccessScreen loginSuccess = new SuccessScreen(username, selectedDomain);
UiApplication.getUiApplication().pushScreen(loginSuccess);
}
}