Open a website when user clicks on a label field on BlackBerry - blackberry

I want my BlackBerry app to open a website when I focus on its name.
Can anybody tell me how to do that?

final LabelField label = new LabelField(url,LabelField.FOCUSABLE);
label.setFocusListener(new FocusChangeListener(){
public void focusChanged(Field field, int eventType) {
if(eventType == FOCUS_GAINED){
BrowserSession bSession = Browser.getDefaultSession();
bSession.displayPage(label.getText());
}
}
});
add(label);

Related

how to show details when click on list filed?

Hi Friend's i want to show details when i click on this list field with image(location)means u take any lat long and show with it a image map.so please help me to solve this problem.
How is it possible please help me.
Thanks
on this link show the list field i am also create like this listfiled and when i click and show details with image map
How is it possible please help me.
Thanks
Here I am giving some example try this (assign index to each field in the list view). You can display your details in NewsScreen().
protected boolean navigationClick(int status, int time) {
int index;
System.out.println("CLICKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
index = this.getFieldWithFocusIndex();
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().pushScreen(new NewsScreen());
}
});
System.out.println("OUTPUTTTTTTTTTTTTTTT"+this.getFieldWithFocusIndex());
return true;
}
you could pass the image map String URI or bitmap byte to the other screen and show it
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().pushScreen(new NewsScreen(IMAGE MAP STRING));
}
});

Not able to set a common Listener in BlackBerry development

I am trying to set a common listener for an Customized button and Bitmap field.I am able to reach in listener but not able to differentiate between two fields.
private class MeaningsDetailsPageListner implements FieldChangeListener{
public void fieldChanged(Field field, int arg1) {
Dialog.alert("Hi");
if(field == bField){
Dialog.alert("Image Clicked");
}else if(field == wordBtn){
Dialog.alert("Button Clicked!!");
}
}
}
In following code wordBtn is my customised button and other is BitmapField.I am getting Hi alert but not able to differentiate further.
Any help would be appreciated.
Although I see what you're trying to do, you're better off adding a FieldChangeListener to each Field individually as an anonymous class. This way you don't have to worry about casting your Field to the correct type when testing for equality inside fieldChanged.
ButtonField b = new ButtonField("Hello!");
b.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Button clicked");
}
});

ObjectChoiceField in blackberry

In my application there is one ObjectChoiceField in MainScreen
i want to get change Listner of ObjectChoiceField after click on index 0.
i had already get click event of ObjectChoiceField after click on index grater than 1 and so on ..
so how can i get instance click event after click on ObjectChoiceField ?
I am not really sure what you are asking for.
In your FieldChangeListener.fieldChanged() method, calling ObjectChoiceField.getSelectedIndex() tells you which index is currently selected. You can look for index 0 from that.
If that is not what you need, then you need to clarify your question better.
ObjectChoiceField choiceField = new ObjectChoiceField();
public void fieldChanged(Field field, int context) {
if(field.equals(choiceField))
{
if(choiceField.getSelectedIndex==0)
{your Code}
}
If you want the value which the user have selected you can do by this way too
ObjectChoiceField choiceField = new ObjectChoiceField();
public void fieldChanged(Field field, int context) {
if(field.equals(choiceField))
{
if(choiceField.getSelectedIndex==0)
{
int index = choiceField.getSelectedIndex();
String s = (String) objectWeather.getChoice(index);
Dialog.inform("selected value is"+s);
}
}
}

Move Focus From PasswordEditField to Next PasswordEditField in blackberry

I am new to BlackBerry and Java. I am trying to figure out but not getting any correct way to implemnt my task. I want to enter 16 digit password. So for that, I have four passwordEditField in HorizontalFieldManager, each passwordEditField allows max 4 digits. When I enter 4 digits in first leftmost passwordEditField, I want to set focus automatically to the following next passwordEditField without any keypress. I used,
passwordEditField = new PasswordEditField("","",4,0){
protected void onUnfocus()
{
this.setFocus(passwordEditField.getIndex()+1,0,0);
}
};
I tried moveFocus(), setFocus(), setCursorPosition() but not getting the focus on to next element. Is there any way i can impelement this task in blackberry.
passwordEditField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String text = passwordEditField.getText().toString();
if (text.length() == 4) {
nextPasswordEditField.setFocus();
}
}
});

Dropdownlist in Blackberry

I need to develop the blackberry application using jave (eclips), can you please help me what are the events for dropdown and how to read the value of dropdown list , i tried using getText() method but its given error, can u please give small example on dropdown list in blackberry
final String[] data = {"A", "B","C","D"};
ObjectChoiceField ocf = new ObjectChoiceField("Set your status", data);
ocf.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
if(context != PROGRAMMATIC)
Dialog.alert(data[ocf.getSelectedIndex()]);
}
});

Resources