Blaze Tama
Blaze Tama

Reputation: 10948

Backberry Java field listener doesn't listen

I have 2 buttons in my code, 'Clear' and 'Login', the problem is the login button can't be clicked, but the clear button works just fine. Where is my mistake?

The code below is the entire project

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);
    }
}

Upvotes: 0

Views: 76

Answers (1)

Govindarao Kondala
Govindarao Kondala

Reputation: 2862

Hi dear you need to add

btnLogIn.setChangeListener(this);

try this

Upvotes: 3

Related Questions