Blackberry storm 9530 tracing touch events while scrolling
hey in my screen there is a an edit field and 2 custom button fields as "OK" and "CANCEL" Below buttonfield there are some more focussable label fields
when i write a name in edit field and press enter then focus comes to "OK" button but how to set focus on "CANCEL" button.
Moreover while scrolling the focus does not automatically move ahead???
what to do may be i m confused with touch events and their handling!!!
Kindly help!!!!!!!!!!!!
Code:
txt_Name = new EditField(TextField.NO_NEWLINE)
{
public void paint(net.rim.device.api.ui.Graphics g)
{
g.setColor(Color.MAROON);
super.paint(g);
}
};
txt_Name.setFont(font);
v1 = new VerticalFieldManager();
开发者_StackOverflow中文版 v1.add(txt_Name );
ButtonField btn1 = new ButtonField("OK",ButtonField.CONSUME_CLICK);
ButtonField btn2 = new ButtonField("CANCEL",ButtonField.CONSUME_CLICK);
v2 = new VerticalFieldManager();
v2.add(btn1);
v2.add(btn2);
LabelField l1 = new LabelField("Hello Moon ",Field.Focussable);
LabelField l2 = new LabelField("Hello Citizen",Field.Focussable);
LabelField l3 = new LabelField("Hello People",Field.Focussable);
LabelField l4 = new LabelField("Hello world",Field.Focussable);
v3 = new VerticalFieldManager();
v3.add(l1);
v3.add(l2);
v3.add(l3);
v3.add(l4);
add(v1);
add(v2);
add(v3);
}
protected boolean navigationClick(int status, int time)
{
if(OK.isFocus())
{
//execute some code
return true;
}
if(CANCEL.isFocus())
{
//execute some code
return true;
}
}
I made just like Mark suggested, separate FieldChangeListeners for each button:
class Scr extends MainScreen {
EditField txt_Name;
ButtonField btnOK;
ButtonField btnCancel;
VerticalFieldManager v1;
VerticalFieldManager v2;
VerticalFieldManager v3;
Font font = Font.getDefault().derive(Font.BOLD, 20);
public Scr() {
txt_Name = new EditField(TextField.NO_NEWLINE) {
public void paint(net.rim.device.api.ui.Graphics g) {
g.setColor(Color.MAROON);
super.paint(g);
}
};
txt_Name.setFont(font);
v1 = new VerticalFieldManager();
v1.add(txt_Name);
btnOK = new ButtonField("OK", ButtonField.CONSUME_CLICK);
btnOK.setChangeListener(
new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
Dialog.inform("OK pressed");
}});
btnCancel = new ButtonField("Cancel", ButtonField.CONSUME_CLICK);
btnCancel.setChangeListener(
new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
Dialog.inform("Cancel pressed");
}});
v2 = new VerticalFieldManager();
v2.add(btnOK);
v2.add(btnCancel);
LabelField l1 = new LabelField("Hello Moon", Field.FOCUSABLE);
LabelField l2 = new LabelField("Hello Citizen", Field.FOCUSABLE);
LabelField l3 = new LabelField("Hello People", Field.FOCUSABLE);
LabelField l4 = new LabelField("Hello world", Field.FOCUSABLE);
v3 = new VerticalFieldManager();
v3.add(l1);
v3.add(l2);
v3.add(l3);
v3.add(l4);
add(v1);
add(v2);
add(v3);
}
}
Now it seems to be OK:
alt text http://img40.imageshack.us/img40/6472/textentered.jpg alt text http://img59.imageshack.us/img59/7574/okpressed.jpg alt text http://img641.imageshack.us/img641/9246/cancelpressed01.jpg
UPDATE
Swati I can click those buttons with Storm simulator using a mouse click.
I can't find any other explanation than cod file in simulator is from old version. You can check it quickly by changing any label text in code and then deploy and check if this change will be applied in app on device. In case if not, this is the old version and you should clean simulator and deploy app once again.
Hope this will help you!
See also BlackBerry - Changes are not getting reflected in my app
txt_Name = new EditField(TextField.NO_NEWLINE)
{
public void paint(net.rim.device.api.ui.Graphics g)
{
g.setColor(Color.MAROON);
super.paint(g);
}
};
txt_Name.setFont(font);
v1 = new VerticalFieldManager();
v1.add(txt_Name );
ButtonField btn1 = new ButtonField("OK",ButtonField.CONSUME_CLICK);
ButtonField btn2 = new ButtonField("CANCEL",ButtonField.CONSUME_CLICK);
h2 = new HorizontalalFieldManager();
h2.add(btn1);
h2.add(btn2);
LabelField l1 = new LabelField("Hello Moon ",Field.Focussable);
LabelField l2 = new LabelField("Hello Citizen",Field.Focussable);
LabelField l3 = new LabelField("Hello People",Field.Focussable);
LabelField l4 = new LabelField("Hello world",Field.Focussable);
v3 = new VerticalFieldManager();
v3.add(l1);
v3.add(l2);
v3.add(l3);
v3.add(l4);
add(v1);
add(h2);
add(v3);
}
protected boolean navigationClick(int status, int time)
{
int index = h2.getFieldwithFocusIndex();
if(h2==0)
{
//execute some code for OK
return true;
}
if(h2==1)
{
//execute some code for cancel
return true;
}
}
You can control the focus order by overriding the "navigationMovement" method on the screen or manager containing the focusable fields, such as the okay and cancel buttons. Just evaluate the arguments passed in to that method, set focus on the desired field using Field.setFocus(), and return true.
As for the focus not moving ahead with scrolling - that's just the way the touchscreen UI works. The focus only moves when you touch a focusable field - so if you aren't touching any focusable fields when you "flick" the screen to scroll, the focus won't change.
精彩评论