I am tring one application where i take one label & one button.
I want when user clicks on that button 'Select Profile' popup screen is open.
when user selects vibration profile then label must be set to " Vibration On " & for other profile it is set as "Vibration Off "
I tried it but that Label is not setting immideatly after selecting profile.
This is my code
public final class MyScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
LabelField lbl;
ButtonField btnOk;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
lbl=new LabelField("Set profile ");
btnOk=new ButtonField("OK");
btnOk.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
try {
ApplicationManager .getApplicationManager().launch("net_rim_bb_profiles_app");
} catch (ApplicationManagerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(NotificationsManager.isVibrateOnly())
{
lbl.setText("Vibration on");
}
else
{
lbl.setText("Vibration Off");
}
}
});
add(lbl);
add(btnOk);
}
}
Pleease please help me ,doing it from 1 week .......
override OnExposed() and wrote in that method following code
invalidate();
if(NotificationsManager.isVibrateOnly())
{
lbl.setText("Vibration on");
}
else
{
lbl.setText("Vibration Off");
}
This works good for me. :) :D
Related
I want to come to home screen when clicking on the back button from my application in blackberry. I have searched for this in google and stackoverflow, But I didn't get any solution. Anybody help for this.
In My Starting Screen i wrote like this for back button.
protected boolean keyDown(int keycode, int time)
{
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
close();
return true;
}
else
{
return super.keyDown(keycode, time);
}
}
In my HomeScreen i wrote like this.
protected boolean keyDown(int keycode, int time)
{
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
UiApplication.getUiApplication().pushScreen(new StartingScreen());
return true;
}
else
{
return super.keyDown(keycode, time);
}
}
From my application HomeScreen I am able to come to starting screen of the my application. after that when i click on back button from starting screen i need to go to blackberry home screen that means i need to exit the app and come out of that. I wrote close(); to come to blackberry home screen. but its not working. it is again coming to my application homescreen.
Override keyDown method in your subclass of MainScreen.
protected boolean keyDown(int keycode, int time) {
int key = Keypad.key(keycode);
if(key==Characters.ESCAPE){
// do something here
return true;
}
return super.keyDown(keycode, time);
}
To come to home screen
while(!(UiApplication.getUiApplication().getActiveScreen() instanceof HomeScreen)){
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
}
I got the Solution... i have written lik this.
public boolean onClose()
{
int choose=Dialog.ask(Dialog.D_YES_NO, "Are you sure Want to Exit?");
if(choose==Dialog.YES)
{
System.exit(0);
}
return true;
}
Try this -
public class yourclass extends MainScreen{
public yourclass(){
}
}
public boolean onClose() {
Application.getApplication().invokeLater(new Runnable() {
public void run() {
//close this screen and push your home screen
}
});
return true;
}
i am new in blackberry developer. i am use a pillsetbutton and pillfieldbutton
but when i am click pillfieldbutton no any action is performed.I am using setchangeListener() method.but no any Action is performed.i am going Through this process.
public DemoPill() {
PillButtonSet objButtonSet=new PillButtonSet();
final PillButtonField objButtonField1=new PillButtonField("NSE");
final PillButtonField objButtonField2=new PillButtonField("BSE");
objButtonSet.add(objButtonField1);
objButtonSet.add(objButtonField2);
this.add(objButtonSet);
bjButtonSet.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
System.out.println("Hi ");
if(field==objButtonField1)
{
System.out.println("This Is NSE Button");
}
else if(field==objButtonField2)
{
System.out.println("This Is BSE Button");
}
}
});
}
}
You are printing it on console. So without debugging the code you will never know if your click is consumed. So just use an event thread to see the output on your screen. I have provided you the sample just check it. It will show the output on your screen. You can also use Dialog.inform(String message ) But its always good to do it on event thread.
public DemoPill() {
PillButtonSet objButtonSet=new PillButtonSet();
final PillButtonField objButtonField1=new PillButtonField("NSE");
final PillButtonField objButtonField2=new PillButtonField("BSE");
objButtonSet.add(objButtonField1);
objButtonSet.add(objButtonField2);
this.add(objButtonSet);
bjButtonSet.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
// System.out.println("Hi ");
if(field==objButtonField1)
{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("objButtonField1 button clicked")
}
});
}
else if(field==objButtonField2)
{
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("objButtonField2 button clicked")
}
});
}
}
});
}
}
May be this will help cheers. :)
You only can view the output of
System.out.println("ANYDATA");
in debug mode not in run.
Try to debug it not to run it.
I want to display button and drop down on a same screen and want to capture it using fieldChnageListener ,i am not able to get how to add these both on the same screen.I have the following code :
ButtonField btnSubmit = new ButtonField("Submit!",
ButtonField.CONSUME_CLICK);
FieldListener listener = new FieldListener();
//assign that listener to the button
btnSubmit.setChangeListener(listener);
add(btnSubmit);
class FieldListener implements FieldChangeListener {
public void fieldChanged(Field f, int context){
//if the submit button is clicked
if (f == btnSubmit){
getCalender();
//if the EditField is empty
if(editField.getText().equals("")){
Dialog.alert("Please enter timezone in the field.");
}else{ // if it is not empty, display the message
Dialog.alert("TimeZone is"+editField.getText()+"!");
timeZone = editField.getText();
}
}
if(f == editField) {
//text changed in the ef-Field (EditField)
}
}
}
how to add a drop down here?
here how can you do this ..
If your class is implementing FieldChangeListner then in its fieldChanged method do like this
public class Demo extends mainScreen implements FieldChangeListener {
public Demo () {
ButtonField btnSubmit = new ButtonField("Submit!",
ButtonField.CONSUME_CLICK);
//assign that listener to the button
btnSubmit.setChangeListener(this);
add(btnSubmit);
}
public void fieldChanged(Field f, int context) {
//if the submit button is clicked
if (f == btnSubmit){
getCalender();
//if the EditField is empty
if(editField.getText().equals("")){
Dialog.alert("Please enter timezone in the field.");
}else{ // if it is not empty, display the message
Dialog.alert("TimeZone is"+editField.getText()+"!");
timeZone = editField.getText();
}
}
if(f == editField) {
//text changed in the ef-Field (EditField)
}
}
}
this should work.
I am creating a BlackBerry application which contains two ObjectChoiceFields. I want to add listeners for each of them. I searched for that but did not find any of useful code.
It is like a country-state selector on websites. I am looking for simple logic, and I have no need of any database oriented solution. Can anyone describe how to add listeners for those two ObjectChoiceField?
I have have attached my code below, but it is only working for country choice field. Nothing happens when I change state choice.
public class MyApplication extends MainScreen implements FieldChangeListener
{
ObjectChouceField choice_c,choice_s;
public MyApplication ()
{
this.setTitle("hai");
choice_c = new MyChoiceField("Select a Country", countryArray);
choice_c.setChangeListener(this);
this.add(choice_c);
choice_s = new MyChoiceField("Select a State", stateArray);
choice_s.setChangeListener(this);
this.add(choice_s);
..................
..................
}
public void fieldChanged(Field field, int context)
{
if(field == choice_category)
{
Dialog.alert("choice country has been pressed");
}
else if(field == choice_round)
{
Dialog.alert("choice state has been pressed");
}
}
}
Have you tried overriding the navigationClick method of the ObjectChoiceField?
Here is an example:
ObjectChoiceField selectionField = new ObjectChoiceField("Select the Country",countryArray)
{
protected boolean navigationClick(int arg0, int arg1)
{
return super.navigationClick(arg0, arg1);
}
};
cf is the ChoiceField. Use the getSelectedIndex to and trigger events accordingly.
cf.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
switch (cf.getSelectedIndex()) {
case 0:
//code here //
break;
default:
break;
}
}
});
I create a custom menu in new class extends popupScreen. I went when the user clock on the menu button the menu display. I use this code
protected boolean keyDown(int keycode, int time) {
if(Keypad.KEY_MENU == Keypad.key(keycode))
{
UiApplication.getUiApplication().popScreen(getScreen());
Menu popup = new Menu();
UiApplication.getUiApplication().pushScreen(popup);
return true;
}
else
return super.keyDown(keycode, time);
}
but I obtain error on this line UiApplication.getUiApplication().pushScreen(popup); causes by pushScreen. How can I change this code or there is another method to display this menu.
try this
protected boolean keyDown(int keycode, int time) {
if(Keypad.KEY_MENU == Keypad.key(keycode))
{
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().popScreen(getScreen());
Menu popup = new Menu();
UiApplication.getUiApplication().pushScreen(popup);
}
return true;
}
else
return super.keyDown(keycode, time);
}
In Blackberry, creating, displaying and hiding of Menu is handled by the system; you will be provided with callbacks at appropriate time. The callbacks you will need to code are:
public boolean onMenu( int instance )
{
return true; // Menu is created
}
public void makeMenu( Menu menu, int instance )
{
MenuItem _desired_menu_item = new MenuItem()
{
public void run()
{
}
}
menu.add( _desired_menu_item );
super.makeMenu( menu, instance)
}
That's it! It would work. Please check Blackberry "UI and Navigation guide" for more details