Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 329
Registered: ‎12-17-2010
My Device: Not Specified
My Carrier: developer

popupScreen with RadioButton Group

hiiiii All

 

I Want to add RadioButtonGroup to to the popup Screen is it possible to add RadioButtonFieldGroup to PopScreen

 

please Help me..

 

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: popupScreen with RadioButton Group

Never tried it myself, but I can see no reason why it would not work.  What happens when you try it?

Developer
Posts: 329
Registered: ‎12-17-2010
My Device: Not Specified
My Carrier: developer

Re: popupScreen with RadioButton Group

when i kept the radiobuttonfield ... i am unable to see the application in simulator.... i dont know why...

 

if i removed these field on popup Screen i can see the application in simulator

Developer
Posts: 204
Registered: ‎07-09-2009
My Device: Not Specified

Re: popupScreen with RadioButton Group

[ Edited ]

Yes, I've successfully used radio buttons on a popup screen.

 

 

class breakfastsReady extends PopupScreen {
RadioButtonField fResponse;

public breakfastsReady() {
RadioButtonGroup gResponse = new RadioButtonGroup();
add(fResponse = new RadioButtonField("Be right down...", gResponse, true));
add(new RadioButtonField("Let me sleep!", gResponse, false));
}

}

 

 

Developer
Posts: 329
Registered: ‎12-17-2010
My Device: Not Specified
My Carrier: developer

Re: popupScreen with RadioButton Group

thank for your reply but again iam unable see my application in simulator...... can you send me you complete code........

Developer
Posts: 204
Registered: ‎07-09-2009
My Device: Not Specified

Re: popupScreen with RadioButton Group

[ Edited ]

Is the application crashing because of an exception?

 

What if you place a breakpoint in main(), can you get that far in the simulator?  if yes, what happens when you step through the popup screen initialization?  Does it get that far, and where does it fail?

 

I'd be happy to look at your code, but the relevant part of mine is as you see above.  I don't see why it should be different than any other type of screen, unless it's too small to accommodate the fields.

 

edit:

 

package sample;

//import java.lang.*;
import java.util.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

class ChelpScr extends PopupScreen implements KeyListener {
  RadioButtonField fdefon;
  Csettings settings = ac.app.settings;
  boolean origdmod = settings.defon;

  public ChelpScr() {
    super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLLBAR | VerticalFieldManager.VERTICAL_SCROLL));
            
      RadioButtonGroup rg = new RadioButtonGroup();
      add(fdefon = new RadioButtonField("ON", rg, settings.defon));
      add(new RadioButtonField("OFF", rg, !settings.defon));
    
    }
    
  public void save() {
    if (settings.defon) {
      if (!fdefon.isSelected()) {
        settings.defon = false;
        settings.changed = true;
        }
      }
    else {
      if (fdefon.isSelected()) {
        settings.defon = true;
        settings.changed = true;
        }
      }
    settings.save(false);
    }
    
  public boolean onSavePrompt() {
    onSave();
    return true;
    }
    
  public boolean onClose() {
    if (isDirty())
      onSavePrompt();
    close();
    return true;
    }

  public boolean keyChar(char k, int s, int t) {
    return false;
    }
  public boolean  keyDown(int K, int t) {
    int k = Keypad.key(K);
    if ((k == Keypad.KEY_END) || (k == Keypad.KEY_ESCAPE)) {
      onClose();
      return true;
      }
    return false;
    }
  public boolean  keyUp(int k, int t) {
    return false;
    }
  public boolean  keyRepeat(int k, int t) {
    return false;
    }
  public boolean  keyStatus(int k, int t) {
    return false;
    }
        
  }
 
 

 

 

Developer
Posts: 329
Registered: ‎12-17-2010
My Device: Not Specified
My Carrier: developer

Re: popupScreen with RadioButton Group

 

package com.popupScreen;

import net.rim.device.api.ui.UiApplication;

public class MainClass extends UiApplication {

	public MainClass() {
		
		pushScreen(new breakfastsReady());
		pushScreen(new PasswordPopupScreen());
		
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		MainClass mainClass = new MainClass();
		mainClass.enterEventDispatcher();
		

	}

}

//.................................................

package com.popupScreen;



import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

class breakfastsReady extends PopupScreen {
  RadioButtonField fResponse;

  public breakfastsReady() {
	  super(new VerticalFieldManager());
    RadioButtonGroup gResponse = new RadioButtonGroup();
    add(fResponse = new RadioButtonField("Be right down...", gResponse, true));
    add(new RadioButtonField("Let me sleep!", gResponse, false));
    }

  }

//......................................

package com.popupScreen;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
public class PasswordPopupScreen extends PopupScreen implements
   KeyListener,TrackwheelListener {
   private String _response;
   private PasswordEditField answer;
  

   private String password = "password";
   public PasswordPopupScreen()
   {
       super(new VerticalFieldManager(),Field.FOCUSABLE);
       LabelField question = new LabelField("Please enter password");
       answer = new PasswordEditField(" ","");
       add(question);
       add(new SeparatorField());
      
       add(answer);
   }
   public void accept() {
       UiApplication.getUiApplication().popScreen(this);
       
   }
   public void close() {
       UiApplication.getUiApplication().popScreen(this);
   }
   public String getResponse() {
       return _response;
   }
   public boolean trackwheelClick(int status, int time) {
       _response = answer.getText();
       if (_response.equals(password)) {
           accept();
       }
       else {
           Dialog.alert("Invalid Password !");
       }
       return true;
   }
   /** Invoked when the trackwheel is released */
   public boolean trackwheelUnclick(int status, int time) {
       return false;
   }
   /** Invoked when the trackwheel is rolled. */
   public boolean trackwheelRoll(int amount, int status, int time) {
       return true;
   }
   public boolean keyChar(char key, int status, int time) {
       boolean retval = false;
       switch (key) {
           case Characters.ENTER:
               _response = answer.getText();
               if (_response.equals(password)) {
                   accept();
               }
               else {
                   Dialog.alert("Invalid Password !");
               }
               retval = true;
               break;
           case Characters.ESCAPE:
               close();
               break;
           default:
               retval = super.keyChar(key,status,time);
       }
       return retval;
   }
   /** Implementation of KeyListener.keyDown */
   public boolean keyDown(int keycode, int time) {
       return false;
   }
   /** Implementation of KeyListener.keyRepeat */
   public boolean keyRepeat(int keycode, int time) {
       return false;
   }
   /** Implementation of KeyListener.keyStatus */
   public boolean keyStatus(int keycode, int time) {
       return false;
   }
   /** Implementation of KeyListener.keyUp */
   public boolean keyUp(int keycode, int time) {
       return false;
   }
}

 

 

Developer
Posts: 204
Registered: ‎07-09-2009
My Device: Not Specified

Re: popupScreen with RadioButton Group

Posted my screen code above.  In yours, pushing those two screens one after the other will not make them pop up in sequence, even though they're popupscreens; the latter would obscure the former until dismissed.

 

Also, I don't know if pushing screens in the application constructor works, but I never do that.  Here's what works for me:

 

package sample;

//import java.lang.*;
import java.util.*;
import net.rim.blackberry.api.menuitem.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
import net.rim.device.api.applicationcontrol.*;


class ac extends UiApplication
{

  public static ac app;
  protected boolean touch=false;
  protected Csettings settings;

  public static void main(String[] args) {
    if (app == null) {
      app = new ac();
      app.init();
      app.enterEventDispatcher();
      }
    else 
      app.requestForeground();
    }  
  
  public ac() {
    touch = Touchscreen.isSupported();  // OSVER 4.7+ only
    settings = Csettings.get();
    }
      
  public void init() {    
    pushScreen(new ChelpScr();
    }

  }

 

That way, the app is instantiated before anything gets done, other than loading the settings and other stuff that can't possibly require an app being instanted to be done.  Maybe it's not necessary in this case, but that's all I can see that I'd change, and that 2-step initialization helps on complex apps.

 

 

Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: popupScreen with RadioButton Group

Are you meaning that you can't see the application icon on the simulator to run it, or the application is behaving in an unexpected fashion?

Developer
Posts: 329
Registered: ‎12-17-2010
My Device: Not Specified
My Carrier: developer

Re: popupScreen with RadioButton Group

I can't see the application icon on the simulator to run it