blackberry jre4.5, highlight URL - blackberry

I have an object that extends Field, I use the paint method to draw text using graphics.drawText. I want to have url, and when the user scrolls over it, it gets highlighted. and when clicked it invokes the browser to the link.
like the normal behaviour in the blackberry.
Please direct me.
Thanks,
Aly

You can use LabelField as a button like this:
LabelField labelField = new LabelField("label to show",FOCUSABLE){
protected boolean invokeAction(int action) {
if ( action == ACTION_INVOKE){
// browsing...
}
return super.invokeAction( action );
}
};

Related

How to make a blackberry BitmapField non focusable in runtime

How to make a blackberry BitmapField non-focusable in runtime? I want make it dimmed based on a certain event.
Extend the BitmapField to override the isFocusable() method like this:
public class FocusableBitmapField extends BitmapField {
//Default value depending on whether you want it that way.
private boolean focusable = true;
public boolean isFocusable() {
return focusable;
}
public boolean setFocusable(boolean focusable) {
this.focusable = focusable;
}
}
Most of times this works:
field.setEditable(false);
You can also create a non-focusable field by passing the style flag Field.NON_FOCUSABLE or Field.FOCUSABLE to the constructor, but once instantiated you cannot change it's focusable state. Even if you could, then the field won't look "dimmed" or "disabled", but simply the focus will jump to the next focusable field after it. An example of this are non-focusable label fields.
UPDATE: This would work for built in fields like EditFields, Checkbox, RadioButtons, etc. In your case, this does not work since a BitmapField is not "editable", it's a read only field. You can make a trick like #adwiv answer shows, but the "disabled" or gray overlay you'll have to implement it yourself.

Add field manager to application Main screen in BlackBerry

I am working with a BlackBerry application for OS 5.0 and later. The application has one screen which displays at the top of screen a Next and a Previous button. and list field also display in this screen at bottom of these both button
When i click on NEXT Button and Previous Button my List will be updated display data..
When i click on NEXT/PREVIOUS Button i have to display small VerticalfieldManager at the center of the screen with Label "Please wait ..." so after design this screen how can we add more field manager in over the another manager ?
Is there any way to display that Field at the application MainScreen like iPhone AppDelegate screen?
btnState.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context)
{ vfm_Middle.add(lblPleasewait);
popup = new PopupScreen(manager);
Thread thread = new Thread()
{
public void run()
{
try
{
Updatelistfield();
stop();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
super.run();
}
public synchronized void stop()
{
// TODO Auto-generated method stub
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// TODO Auto-generated method stub
//popup.delete(vfm_Main);
//popup.deleteAll();
//vfm_Main.delete(lblPleasewait);
//lblPleasewait.setText(null);
}
});
}
};
thread.start();
}
});
The proper way of doing that is with a blocking dialog. In BB API this can be done as follows:
VerticalFieldManager manager = new VerticalFieldManager();
manager.add(new LabelField("Please Wait..."));
Screen popup = new PopupScreen(manager);
//Show the pop-up the same way you push a regular screen
This has the advantage of blocking the GUI: if the user pushes the menu or esc key it doesn't have any effect.
If you want to do it in your screen without dialogs, then you can add an empty VerticalFieldManager which you can fill with a label when the message has to be shown. This way, instead of updating the entire screen, only the Manager is refreshed. But then you should write the logic to not letting the user push any button or menu key (or ignoring key press).

CheckboxField checked in Blackberry

How will i be able to recognise a check on the Checkboxfield.
Like if a user checks on a check box, a notification is generated.
BR,
Suppi
CheckBoxField class inherited from Field class, which means you should be able to create an action listener.
Use setActionListener method and override the fieldChanged method to do whatever you want.
checkBox.setChangeListener(new FieldChangeListener() {
public void fieldChanged(...params ... ) {
//your code
}
});

Blackberry screen navigation

I want to know how to go from one screen to another by clicking a button that I have added to a MainScreen. I mean just like we do in the Android onClick event for a button - start another startActivity.
In the event handler for the button click, just "push" the screen that you want to appear next, and it will be pushed to the top of the screen stack. For example:
UiApplication.getUiApplication().pushScreen(nextScreen);
This will be better, using FieldChangeListener
button.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
UiApplication.getUiApplication().pushScreen(new NextScreen());
}
});
This is the alternative way than using,
UiApplication.getUiApplication.involeLater()
{};

Is there any other Method other than pushscreen to go to next Screen?

I want to show another screen, when the user clicks in a ListField.
But my class containing ListField extends MainScreen!
How can I push to another screen?
Is there any way other than pushScreen to go to another screen?
OverRide NavigationClick ,below is the example
public boolean navigationClick(int status,int time){
Field focus = _countries.getLeafFieldWithFocus();
if(focus instanceof ListField){
ListField listField = (ListField)focus;
country = listField.getCallback().get(listField,listField.getSelectedIndex()).toString();//this will return the text clicked from the listfield
TransitionContext transition = new TransitionContext(TransitionContext.TRANSITION_FADE);
transition.setIntAttribute(TransitionContext.ATTR_DURATION,500);
transition.setIntAttribute(TransitionContext.ATTR_DIRECTION,TransitionContext.DIRECTION_DOWN);
transition.setIntAttribute(TransitionContext.ATTR_STYLE,TransitionContext.STYLE_PUSH);
UiEngineInstance engine = Ui.getUiEngineInstance();
engine.setTransition(MyApp.scr,MyScreen._radio,UiEngineInstance.TRIGGER_PUSH,transition);
MyApp.scr=null;
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(MyScreen._radio);
}
return true;
}

Resources