0
我在我的代碼中有2個按鈕,'清除'和'登錄',問題是登錄按鈕無法被點擊,但清除按鈕工作得很好。 我的錯誤在哪裏?Backberry Java字段監聽器不聽
下面的代碼是整個項目
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);
}
}
OMG WTF..this是我問過的最愚蠢的問題,這一個已經花了我幾小時(真的,3小時)@ _ @ 無論如何謝謝:D –
事情發生這樣的事不用擔心 –