I have two Radiobutton and on one RadioButton click i want to hide editfield, so please can anyone help me.
Thanks, In advance.
Perhaps you could try using Managers to delete and add fields. Try:
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public final class MyScreen extends MainScreen {
private BasicEditField bef = new BasicEditField();
private VerticalFieldManager manager = new VerticalFieldManager();
private RadioButtonGroup rbg = new RadioButtonGroup();
public MyScreen() {
setTitle("Hide Control Demo");
manager.add(bef);
add(manager);
RadioButtonField rbf1 = new RadioButtonField("Option 1", rbg, true);
RadioButtonField rbf2 = new RadioButtonField("Option 2", rbg, false);
add(rbf1);
add(rbf2);
rbf2.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (bef.getManager() != null && rbg.getSelectedIndex() == 1) {
manager.delete(bef);
System.out.println("Option 2 Selected");
}
}
});
}
}
Try this it will work
package com.hb;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class Startup extends UiApplication{
public static void main(String[] args) {
Startup start=new Startup();
start.enterEventDispatcher();
}
public Startup() {
pushScreen(new screen());
}
}
class screen extends MainScreen implements FieldChangeListener
{
RadioButtonField field1,field2;
private EditField edit1;
private VerticalFieldManager edit_mgr=null;
public screen() {
HorizontalFieldManager hr=new HorizontalFieldManager();
RadioButtonGroup g=new RadioButtonGroup();
field1=new RadioButtonField("edit", g,true);
field1.setChangeListener(this);
hr.add(field1);
field2=new RadioButtonField("no edit", g,false);
field2.setChangeListener(this);
hr.add(field2);
add(hr);
edit_mgr=new VerticalFieldManager();
edit1=new EditField();
edit1.setEditable(true);
edit_mgr.add(edit1);
add(edit_mgr);
}
public void fieldChanged(Field field, int context) {
if(field==field1){
synchronized (UiApplication.getEventLock()) {
edit1.setEditable(true);
}
}else if(field==field2){
synchronized (UiApplication.getEventLock()) {
edit1.setEditable(false);
}
}
}
}
Related
I want to make an existing iPhone application in blackberry. Now I am in feasibility study phase for mockup design. I was looking for implementing the iPhone toolbar (as shown in below attached image) kind of functionality for blackberry. I am not really looking to implement the same, it can be changed according to the blackberry UI guidelines.
After doing round of googleing i came across few things listed below
Use menu items and place icon
Create ToolBar same as iPhone, But again the API is available from BB SDK 6.0 onwards. I am keen to implement in BB SDK 5.0. We can customize the same but, I believe that is gonna be a huge effort.
Some reference links
BlackBerry - Custom menu toolbar
how to create iphone like tabs layout in blackberry
http://docs.blackberry.com/en/developers/deliverables/17965/Toolbars_6_0_1137042_11.jsp
Please suggest any other best way to implement the same, without violating the blackberry usability guidelines and could be best suited for my requirements.
You can use the Advanced UI components, we use them in our projects and they usually do the trick.
The code is open source, and you can extend them if you need to.
try this -
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FocusChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class tabbar extends UiApplication {
public tabbar() {
TabControlScreen screen = new TabControlScreen();
pushScreen(screen);
}
/**
* #param args
*/
public static void main(String[] args) {
tabbar app = new tabbar();
app.enterEventDispatcher();
}
private class TabControlScreen extends MainScreen implements FocusChangeListener {
private VerticalFieldManager tabArea;
private LabelField tab1Heading;
private LabelField tab2Heading;
private LabelField tab3Heading;
private LabelField tab4Heading;
private VerticalFieldManager tab1Manager;
private VerticalFieldManager tab2Manager;
private VerticalFieldManager tab3Manager;
private VerticalFieldManager tab4Manager;
BitmapField bit,bit1,bit2,bit3;
public TabControlScreen() {
HorizontalFieldManager hManager = new HorizontalFieldManager(FIELD_HCENTER);
final Bitmap header_logo = Bitmap.getBitmapResource("1.png");
bit=new BitmapField(header_logo,BitmapField.FOCUSABLE |BitmapField.HIGHLIGHT_FOCUS);
final Bitmap header_logo1 = Bitmap.getBitmapResource("3.png");
bit1=new BitmapField(header_logo1,BitmapField.FOCUSABLE |BitmapField.HIGHLIGHT_FOCUS);
final Bitmap header_logo2 = Bitmap.getBitmapResource("2.png");
bit2=new BitmapField(header_logo2,BitmapField.FOCUSABLE |BitmapField.HIGHLIGHT_FOCUS);
final Bitmap header_logo3 = Bitmap.getBitmapResource("4.png");
bit3=new BitmapField(header_logo3,BitmapField.FOCUSABLE |BitmapField.HIGHLIGHT_FOCUS);
bit.setFocusListener(this);
bit1.setFocusListener(this);
bit2.setFocusListener(this);
bit3.setFocusListener(this);
hManager.add(bit);
hManager.add(bit1);
hManager.add(bit2);
hManager.add(bit3);
add(hManager);
tab1Manager = new VerticalFieldManager();
tab2Manager = new VerticalFieldManager();
tab3Manager = new VerticalFieldManager();
tab4Manager = new VerticalFieldManager();
tabArea = displayTab1();
add(tabArea);
}
public void focusChanged(Field field, int eventType) {
if (tabArea != null) {
if (eventType == FOCUS_GAINED) {
if (field == bit) {
delete(tabArea);
tabArea = displayTab1();
add(tabArea);
} else if (field == bit1) {
delete(tabArea);
tabArea = displayTab2();
add(tabArea);
} else if (field == bit2) {
delete(tabArea);
tabArea = displayTab3();
add(tabArea);
}
else if (field == bit3) {
delete(tabArea);
tabArea = displayTab4();
add(tabArea);
}
}
}
}
public VerticalFieldManager displayTab1() {
if (tab1Heading == null) {
tab1Heading = new LabelField("1");
ButtonField settings=new ButtonField("Settings",ButtonField.FIELD_LEFT);
//ButtonField add=new ButtonField("Add",ButtonField.FIELD_RIGHT);
//JustifiedHorizontalFieldManager JustifiedHorizontalFieldManager=new JustifiedHorizontalFieldManager(settings,add,true);
tab1Manager.add(settings);
}
return tab1Manager;
}
public VerticalFieldManager displayTab2() {
if (tab2Heading == null) {
tab2Heading = new LabelField("2");
tab2Manager.add(tab2Heading);
}
return tab2Manager;
}
public VerticalFieldManager displayTab3() {
if (tab3Heading == null) {
tab3Heading = new LabelField("3");
tab3Manager.add(tab3Heading);
}
return tab3Manager;
}
public VerticalFieldManager displayTab4() {
if (tab4Heading == null) {
tab4Heading = new LabelField("4");
tab4Manager.add(tab4Heading);
}
return tab4Manager;
}
}
}
As I'm novice in Blackberry/Java development, I don't know how to use "telugu" font in my Blackberry application. Please give an example.
see the difference between three simulators
9300-OS6 not displaying
9790-os7 displays only in this device .
9900-os7 even OS7 it is not displaying.
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import java.util.*;
public class FontLoadingDemo extends UiApplication
{
public static void main(String[] args)
{
FontLoadingDemo app = new FontLoadingDemo();
app.enterEventDispatcher();
}
public FontLoadingDemo()
{
pushScreen(new FontLoadingDemoScreen());
}
}
class FontLoadingDemoScreen extends MainScreen
{
public FontLoadingDemoScreen()
{
setTitle("Font Loading Demo");
LabelField helloWorld = new LabelField("Hello World");
if (FontManager.getInstance().load("Myfont.ttf", "MyFont", FontManager.APPLICATION_FONT) == FontManager.SUCCESS)
{
try
{
FontFamily typeface = FontFamily.forName("MyFont");
Font myFont = typeface.getFont(Font.PLAIN, 50);
helloWorld.setFont(myFont);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
}
add(helloWorld);
}
}
Source: http://docs.blackberry.com/en/developers/deliverables/11958/Load_and_use_a_custom_font_899948_11.jsp
I edit Blackberry_App_Descriptor.xml to make my app is "Auto run on start up". My app have 3 classes, myApp, screen1 and screen2. MyApp with main method to push screen1. in screen1 have a button to push screen 2. It run OK when I launch appplication manualy. (click icon of App )
Problem is:
I use RealTimeListener to always check time each minutes, if it is 1h30 it will push screen1, ( I used method postGlobalScreen to push Screen1 ). And it pushed success. But i can use the button on this screen1, I clicked it and it not push to screen2.
I try to use Alternate Entry point to check time and push screen1 but it have the same result.
Can anybody help me solve and explain clearly about this problem ?
// MyApp.java
public class MyApp extends UiApplication implements RealtimeClockListener
{
/**
* Entry point for application
* #param args Command line arguments (not used)
*/
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public MyApp()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new Screen1());
addRealtimeClockListener(this);
}
public void clockUpdated() {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int minute = Calendar.getInstance().get(Calendar.MINUTE);
if(hour==1 && minute == 30){
UiApplication.getUiApplication().pushGlobalScreen(new Screen1(),1,UiEngine.GLOBAL_MODAL);
}
}
}
//Screen1.java
public final class Screen1 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen1()
{
button = new ButtonField("Screen 1 ");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
UiApplication.getUiApplication().pushScreen(new Screen2());
}
}
}
//Screen2.java
public final class Screen2 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen2()
{
button = new ButtonField("Screen2");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
UiApplication.getUiApplication().pushScreen(new Screen1());
}
}
}
Please try following. here concentrate on two points
1)Application run in background background
2)send background application into foreground
package mypackage;
import java.util.Calendar;
import net.rim.device.api.system.RealtimeClockListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;
public class MyApp extends UiApplication implements RealtimeClockListener
{
/**
* Entry point for application
* #param args Command line arguments (not used)
*/
public static MyApp theApp=null;
public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
theApp = new MyApp();
theApp.enterEventDispatcher();
}
/**
* Creates a new MyApp object
*/
public MyApp()
{
// Push a screen onto the UI stack for rendering.
pushScreen(new Screen1());
addRealtimeClockListener(this);
}
public void clockUpdated() {
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int minute = Calendar.getInstance().get(Calendar.MINUTE);
// if(hour==1 && minute == 30){
if(!theApp.isForeground())
{
UiApplication.getUiApplication().pushGlobalScreen(new Screen1(),1,UiEngine.GLOBAL_MODAL);
}
}
}
screen1.java
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
public final class Screen1 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen1()
{
button = new ButtonField("Screen 1 ");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
close();
MyApp.theApp.requestForeground();
UiApplication.getUiApplication().pushScreen(new Screen2());
}
}
public boolean onClose() {
MyApp.theApp.requestBackground();
return true;
}
}
screen2.java
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
public final class Screen2 extends MainScreen implements FieldChangeListener
{
/**
* Creates a new MyScreen object
*/
ButtonField button;
public Screen2()
{
button = new ButtonField("Screen2");
button.setChangeListener(this);
add(button);
}
public void fieldChanged(Field field, int context) {
if(field==button){
UiApplication.getUiApplication().pushScreen(new Screen1());
}
}
}
Plz give the code or function how to clear the ListField and update the ListField .
Suppose i want to display some multiple text( Project Name, Project Manager )extracted from JSON object , in a ListField.
I am able to display this strings in the ListField but one more feature i need to add ie.. above the ListField there should be a ButtonField and when the user clicks on the ButtonField the ListField should display the string in sorted manner base on Project Name. So i need to clear the ListField
Code for NetworkingMainScreen is
package src1;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import java.util.Vector;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.UiApplication;
class NetworkingMainScreen extends MainScreen
{
private EditField urlField;
private BitmapField imageOutputField;
private RichTextField textOutputField;
private ListField prjctlist_Field;
private Vector prjct_list_v = new Vector();
VerticalFieldManager vfm;
private String prjts;
public int total_prjcts;
JSONArray data_json_array;
JSONObject outer;
ListField myList;
private Vector v_prj_title;
private Vector v_prj_mgr;
private Vector send_vector;
private Vector send_vector3;
private Vector send_vector4;
private String t1,t2;
public JSONArray jsArrPrjts;
ListCallBack callback;
ButtonField sort;
NetworkingMainScreen()
{
// Screen2 s = new Screen2();
// UiApplication.getUiApplication.pushScreen(s);
setTitle("Networking");
urlField = new EditField("URL:", "http://iphone.openmetrics.com/apps/mattson/api.html?action=login&user=Nathan&password=coffee00&server=exp.lcgpence.com;deviceside=true");
textOutputField = new RichTextField();
imageOutputField = new BitmapField();
add(urlField);
add(new SeparatorField());
add(new LabelField("Text retrieved:"));
add(textOutputField);
myList = new ListField();
callback = new ListCallBack();
myList.setRowHeight(80);
myList.setCallback(callback);
add(myList);
}
protected void makeMenu(Menu menu, int instance)
{
super.makeMenu(menu, instance);
menu.add(new MenuItem("Get", 10, 10) {
public void run() {
getURL();
}
});
}
private void getURL()
{
HttpRequestDispatcher dispatcher = new HttpRequestDispatcher(urlField.getText(),"GET", this);
dispatcher.start();
}
public void requestSucceeded(byte[] result, String contentType)
{
if (contentType.startsWith("text/")) {
synchronized (UiApplication.getEventLock())
{
String strResult = new String(result);
try
{
JSONObject joPrjt = new JSONObject(strResult);
String res_code = joPrjt.optString("responseCode");
if( res_code.equals("1"))
{
data_json_array = new JSONArray();
data_json_array = joPrjt.optJSONArray("data");
int s = data_json_array.length();
v_prj_title = new Vector();
v_prj_mgr = new Vector();
outer = new JSONObject();
for(int i=0; i<s; i++)
{
//outer = new JSONObject();
outer = data_json_array.getJSONObject(i);
String job_no = outer.optString("job_number");
String contract_date = outer.optString("contract_date");
String project_title = outer.optString("project_title");
String project_manager = outer.optString("project_manager");
String created_date = outer.optString("created_date");
String project_name = outer.optString("project_name");
v_prj_title.addElement(project_title);
v_prj_mgr.addElement(project_manager);
}
UiApplication.getUiApplication().pushScreen(new Screen2(v_prj_title,v_prj_mgr,0,v_prj_title,v_prj_mgr));
}
else
{
Dialog.alert("Web page connected but not the requested page");
}
}
catch(JSONException e)
{
e.printStackTrace();
System.out.println("key not found catched " + e);
}
}
}
else
{
synchronized (UiApplication.getEventLock()) {
Dialog.alert("Unknown content type: " + contentType);
}
}
}
public void requestFailed(final String message)
{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert("Request failed. Reason: " + message);
}
});
}
}
Code for Screen2 is
package src1;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import java.util.Vector;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
class Screen2 extends MainScreen implements FieldChangeListener
{
JSONArray j_array;
JSONObject j_object;
CustomButtonField bf1;
Vector v_prj_title,v_prj_mgr,v_job_no,v_created_date,v_prj_name,send_vector;
Vector main_v_prj_title,main_v_prj_mgr;
String job_no,contract_date,project_title,project_manager,created_date,project_name;
VerticalFieldManager vfm;
ListField myList;
ListCallBack callback;
int pic_status;
int b;
String t1,t2;
String temp1,temp2,f1,f2;
// ListField prjctlist_Field;
Screen2(Vector v_prj_title2,Vector v_prj_mgr2,int pic_status,Vector main_v_prj_title_o2,Vector main_v_prj_mgr_o2)
{
this.main_v_prj_title = main_v_prj_title_o2;
this.main_v_prj_mgr = main_v_prj_mgr_o2;
this.v_prj_title = v_prj_title2;
this.v_prj_mgr = v_prj_mgr2;
this.pic_status = pic_status;
bf1 = new CustomButtonField("Name",pic_status,0);
bf1.setChangeListener(this);
vfm = new VerticalFieldManager();
vfm.add(bf1);
int s = v_prj_title.size();
myList = new ListField();
callback = new ListCallBack();
myList.setRowHeight(80);
myList.setCallback(callback);
for(int i=0;i<s;i++)
{
myList.insert(i);
t1 = v_prj_title.elementAt(i).toString();
send_vector = new Vector(2);
send_vector.addElement(t1);
t2 = v_prj_mgr.elementAt(i).toString();
send_vector.addElement(t2);
callback.insert(send_vector,i);
}
vfm.add(myList);
add(vfm);
}
public void fieldChanged(Field field, int context)
{
if(field == bf1)
{
if(pic_status == 0)
{
b =1;
int s = v_prj_title.size();
for(int i=0;i<s;i++)
{
for(int t=i+1;t<s;t++)
{
temp1 = (String)v_prj_title.elementAt(i);
temp2 = (String)v_prj_title.elementAt(t);
if(temp1.compareTo(temp2)>0)
{
//System.out.println("Comparision Executed :"+temp1 + " is greater than " + temp2);
f1 = (String)v_prj_mgr.elementAt(i);
f2 = (String)v_prj_mgr.elementAt(t);
v_prj_title.setElementAt(temp1,t);
v_prj_title.setElementAt(temp2,i);
v_prj_mgr.setElementAt(f1,t);
v_prj_mgr.setElementAt(f2,i);
}
}
}
UiApplication.getUiApplication().pushScreen(new Screen2(main_v_prj_title,main_v_prj_mgr,b,main_v_prj_title,main_v_prj_mgr));
}
if(pic_status == 1)
{
b=0;
UiApplication.getUiApplication().pushScreen(new Screen2(main_v_prj_title,main_v_prj_mgr,b,main_v_prj_title,main_v_prj_mgr));
}
}
}
}
one more thing i need to clearify is that in my above code firstly i have parsed the JSON object in NetworkingMainScreen and if the JSON parsing is success i have push a new screen name Screen2 passing the stored Vector to the Screen2. The Screen2 performs ListField drawings or should i perform the ListField drawing in NetworkingMainScreen class only.
For details about the items i need to display plz look **http://iphone.openmetrics.com/apps/mattson/api.html?action=login&user=Nathan&password=coffee00&server=exp.lcgpence.com&output=data**
Implement ListFieldCallback in your screen, you can then handle the drawing of your rows however you want in drawListRow.
I am writing a small demo program to display a message box in to run in blackberry. As soon as I click the OK button on the dialog, it throws me a JVM Error 104, uncaught:runtimeexception. Any help please? Here is the code :
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class My_First_App extends UiApplication
{
public static void main(String[] args)
{
My_First_App theApp = new My_First_App();
theApp.enterEventDispatcher();
}
public My_First_App()
{
pushScreen(new My_First_AppScreen());
}
}
final class My_First_AppScreen extends MainScreen
{
public My_First_AppScreen()
{
super();
HorizontalFieldManager _fieldmanager;
_fieldmanager = new HorizontalFieldManager();
/* declare one label to how the application title */
LabelField applicationtitle = new LabelField("Demo",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
ButtonField _pairMe = new ButtonField("PairMe");
FieldChangeListener listenerPairMe = new FieldChangeListener() {
public void fieldChanged(Field field, int context){
Dialog.alert("You clicked the button!");
}
};
/*set the title*/
add(_fieldmanager);
setTitle(applicationtitle);
_fieldmanager.add(_pairMe);
_pairMe.setChangeListener(listenerPairMe);
}
public boolean onClose()
{
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}
create a new workspace. It's related to Eclipse, not to your code