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
abhi007tyagi
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel
Accepted Solution

Drop Down Error

Hi,

 

I am creating a drop down list of cities.

but when I select one operation occurs according to the first entry in the list

 

I want to select a city from drop-down list and click next button to send the selected city to next screen

 

please have a look in my code and correct me

 

 

Thanks

Abhinav

 

Code::

 

 

String choices[] = {"New Delhi","New York","London"};
        //int iSetTo = 0;
        ObjectChoiceField ocf = new ObjectChoiceField("Select City",choice);     //,iSetTo);
        //ocf.setChangeListener(this);
        ct = ocf.getSelectedIndex();
        System.out.println("@@@@@@@ City ::: "+ct+" ::: "+ocf.getChoice(ct));
        
        
        add(new SeparatorField());
        
        btnNextScreen = new ButtonField("Next", ButtonField.CONSUME_CLICK|ButtonField.FIELD_VCENTER);
        btnNextScreen.setChangeListener(this);
        
        
        this.add(ocf);
        this.add(btnNextScreen);

 

----

----

-----

public void fieldChanged(Field field, int context) {
        if( field ==  btnNextScreen)
       {
            -----

            ------

 

}

 

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Please use plain text.
Developer
nitinverma274
Posts: 950
Registered: ‎06-22-2010
My Device: 9550

Re: Drop Down Error

Look at this

 

String choices[] = {"New Delhi","New York","London"};

ObjectChoiceField ocf = new ObjectChoiceField("Select City",choices);
ocf.setChangeListener(this);
add(ocf);
System.out.println("@@@@@@@ City ::: "+ct+" ::: "+ocf.getChoice(ct));


add(new SeparatorField());

btnNextScreen = new ButtonField("Next", ButtonField.CONSUME_CLICK|ButtonField.FIELD_VCENTER);
btnNextScreen.setChangeListener(this);


this.add(ocf);
this.add(btnNextScreen);

//

 

fieldChanged Method

 


public void fieldChanged(Field field, int context) { if( field == btnNextScreen) { ct = ocf.getSelectedIndex(); String str = ocf.getChoice(ct); UiApplication.getUiApplication().pushScreen(anotherscreen(str)); }

Feel free to ask if you have doubt.

 

------------------------------------------------------------------------------------
Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.

 

Please use plain text.
Developer
abhi007tyagi
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: Drop Down Error

Resolved after  commenting  

this.add(ocf);

 

 

Thanks a lot

 Abhinav

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Please use plain text.
Contributor
alpachino
Posts: 22
Registered: ‎03-23-2011
My Device: torch
My Carrier: Student

Re: Drop Down Error

I want to get back a value that I select with my drop-down list. When I run with debugger, my code plants in step of getting back the index of element selected. Please help if you locate a problem.

public class Day extends MainScreen {

	public ObjectChoiceField hourField;
	public  String day[]= {"Monday","Tuesday", "Wednesday", "Thursday", "Friday", "saturday", "sunday"};
	
	public Day()

	{
		super();
		LabelField title = new LabelField("DAY",
				LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
		setTitle(title);
		add(new RichTextField("Choose the day"));
		add(new SeparatorField());

		ObjectChoiceField listday = new ObjectChoiceField("Days :", day);
		add(listday);
	
	}

	
	MenuItem Validate = new MenuItem("Validate", 100, 0) {
		public void run() {
			
			
			
			int i =  listday.getSelectedIndex(); 
			String str = (String) hourField.getChoice(i);
  
			UiApplication.getUiApplication().pushScreen(new Show());

			UiApplication.getUiApplication().popScreen(getScreen());

		}
	};

	protected void makeMenu(Menu menu, int instance) {
	
		menu.add(Validate);

		super.makeMenu(menu, instance);
	}

	public boolean onClose() {
		Dialog.alert("Goodbye!");
		System.exit(0);
		return true;
	}


}

 

Please use plain text.