Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 27
Registered: ‎02-02-2012
My Device: BB 9800
My Carrier: Airtel
Accepted Solution

ListField,ObjectChoiceField,Buttonfield problem with navigationonclick

Hi,

 

In my screen I have listfield,ButtonField,ObjectChoiceField and CheckboxField,

I implementated navigationClick method.

How to serperate listeners?

 

Thanks

Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationonclick

i don't understand your question.

do you mean how to check which field has been clicked?
you can use getLeafFieldWithFocus to do that.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 27
Registered: ‎02-02-2012
My Device: BB 9800
My Carrier: Airtel

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationonclick

I set the seperate listeners for ButtonField and ObjectChoiceField. 

But not working

here is my code

 

public EventListScreen() {

final ObjectChoiceField ocf = new ObjectChoiceField("", SQLManager.puneAreas);
ocf.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (field == ocf) {
if (context != PROGRAMMATIC) {
reloadListFieldForArea(ocf.getSelectedIndex());
}
}
}

});
add(searchBtn);

FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField buttonField = (ButtonField) field;
if (buttonField == sendBtn) {
if (usernameFld.getTextLength() > 0) {
// searchListField.reloadSearchListField(data);
data.removeAllElements();
reloadListFieldForArea(usernameFld.getText());
} else {
Dialog.alert("Enter Text");
usernameFld.setFocus();
}
}
}
};
searchBtn = new ButtonField("Search", ButtonField.FIELD_RIGHT
| ButtonField.CONSUME_CLICK);
searchBtn .setChangeListener(listener);
add(searchBtn);


eventListField = new EventListField(dataArray);
add(eventListField )
}

 

protected boolean touchEvent(TouchEvent message) {
switch (message.getEvent()) {
case TouchEvent.CLICK:
fieldChangeNotify(1);
// fall through
case TouchEvent.UNCLICK:
return true;
}
return super.touchEvent(message);
}


protected boolean navigationClick(int status, int time) {

if (this.eventListField.isFocus()) {
int row = eventListField.getSelectedIndex();
if (row != -1) {
itemSelection(row);
return true;
}
}
else
{
this.fieldChangeNotify(2);
return false;
}

return true;

}

 

Developer
Posts: 27
Registered: ‎02-02-2012
My Device: BB 9800
My Carrier: Airtel

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationonclick

where i am missing? here is code

 

public EventListScreen() {

final ObjectChoiceField ocf = new ObjectChoiceField("", SQLManager.puneAreas);
ocf.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (field == ocf) {
if (context != PROGRAMMATIC) {
reloadListFieldForArea(ocf.getSelectedIndex());
}
}
}

});

 

FieldChangeListener listener = new FieldChangeListener() {

public void fieldChanged(Field field, int context) {
ButtonField buttonField = (ButtonField) field;
if (buttonField == searchBtn ) {
if (usernameFld.getTextLength() > 0) {
// searchListField.reloadSearchListField(data);
data.removeAllElements();
reloadListFieldForArea(usernameFld.getText());
} else {
Dialog.alert("Enter Text");
usernameFld.setFocus();
}
}
}
};
searchBtn = new ButtonField("Search", ButtonField.FIELD_RIGHT
| ButtonField.CONSUME_CLICK);
searchBtn .setChangeListener(listener);
add(searchBtn);


eventListField = new EventListField(dataArray);
add(eventListField )
}

 

protected boolean touchEvent(TouchEvent message) {
switch (message.getEvent()) {
case TouchEvent.CLICK:
fieldChangeNotify(1);
// fall through
case TouchEvent.UNCLICK:
return true;
}
return super.touchEvent(message);
}


protected boolean navigationClick(int status, int time) {

if (this.eventListField.isFocus()) {
int row = eventListField.getSelectedIndex();
if (row != -1) {
itemSelection(row);
return true;
}

else
{
this.fieldChangeNotify(2);
return false;
}

return true;

}

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationonclick

[ Edited ]

Only looked very briefly, but this looks wrong;

 

public void fieldChanged(Field field, int context) {
ButtonField buttonField = (ButtonField) field;
if (buttonField == sendBtn) {

 

I think you want:

 

public void fieldChanged(Field field, int context) {
if (field == sendBtn) {

 

 

Think about this code change and what it means.


 

Developer
Posts: 27
Registered: ‎02-02-2012
My Device: BB 9800
My Carrier: Airtel

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationonclick

Problem is when i click on Button it executes the listfield click event and navgate to other screen.

I am testing on devices which are not having touch feature

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationClick

Have you debugged this code and worked out how it is getting from the ButtonField to the ListField?  That sounds impossible if you have different Listeners for each Field.  Since ListField does not as supplied have a 'click' listener, I suspect you have added this yourself.  Perhaps there is a problem in that code?

Developer
Posts: 27
Registered: ‎02-02-2012
My Device: BB 9800
My Carrier: Airtel

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationClick

for listfield i used navigationClick not any custom listener.

I debugged the code and it takes me every time there  in navigationClick when i click.

 

protected boolean navigationClick(int status,int time){
if ((status & KeypadListener.STATUS_TRACKWHEEL) != KeypadListener.STATUS_TRACKWHEEL)
{
int row = eventListField.getSelectedIndex();
if (row != -1) {
itemSelection(row);
fieldChangeNotify(1);
return true;
}
}
else
{
fieldChangeNotify(1);
return super.navigationClick(status, time);
}
return true;
}

Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationClick

that should work well if you overwrite the method of listfield.
if you override it for the whole screen: not so much.

navigationclick is called before any changelisteners, as a changelistener is a member of its field, and events are propagated downwards (from screen to manager to submanager etc to field)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 27
Registered: ‎02-02-2012
My Device: BB 9800
My Carrier: Airtel

Re: ListField,ObjectChoiceField,Buttonfield problem with navigationClick

Ok, there i was wrong!

Thanks simon.

so how can set changelistener or navigationclick to ListField object?

in such a way that my ButtonField and ListField also listen to there events.