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
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia
Accepted Solution

ListField in Blackberry---open new screen after click listfield items

[ Edited ]

 

Hi friends I am new to Blackberry java development

 

can anybody will suggest me how to code to open new screen after clicking ListField item

is it navigationClick() or somthing

 

 

Thanks 

Himanshu sharma

Beginner

Please use plain text.
Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold
My Carrier: Vodafone India

Re: ListField in Blackberry---open new screen after click listfield items

Check the below code

protected boolean navigationClick(int status, int time) {
UiApplication.getUiApplication().pushScreen(new YourNewClass());
return true;
}

Thank you
warm regards
Mohammed Aziz
Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: ListField in Blackberry---open new screen after click listfield items

Thanks for reply ..but tell me where should i use this code...in my code 

 

code is given below

 

 

 

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.component.table.*;
import net.rim.device.api.ui.FieldChangeListener;


public class SimpleListDemo extends UiApplication
{
public static void main(String[] args)
{
SimpleListDemo theApp = new SimpleListDemo();
theApp.enterEventDispatcher();
}
public SimpleListDemo()
{
pushScreen(new SimpleListScreen());
}

class SimpleListScreen extends MainScreen implements FieldChangeListener
{
public SimpleListScreen()
{
super(Manager.NO_VERTICAL_SCROLL);
setTitle("Simple List Demo");
add(new LabelField("Blackberry Team", LabelField.FIELD_HCENTER));
add(new SeparatorField());
Manager mainManager = getMainManager();
mainManager.setMargin(0,0,0,50);
SimpleList listField = new SimpleList(mainManager);

 

listField.add("Mr.Sushil");///////////////// i want to open a new sceen on click Mr.sushil item tell me plz
listField.add("Mr.Anantha");
listField.add("Mr.Himanshu");
}
}

public void fieldChange(Field field , int context)
{


}
}

Please use plain text.
Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold
My Carrier: Vodafone India

Re: ListField in Blackberry---open new screen after click listfield items

Just Copy this and paste in your App

 

package mypackage;

import net.rim.device.api.command.CommandHandler;
import net.rim.device.api.command.ReadOnlyCommandMetadata;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.component.table.SimpleList;
import net.rim.device.api.ui.container.MainScreen;

public class SimpleListDemo extends UiApplication {
	public static void main(String[] args) {
		SimpleListDemo theApp = new SimpleListDemo();
		theApp.enterEventDispatcher();
	}

	public SimpleListDemo() {
		pushScreen(new SimpleListScreen());
	}

	class SimpleListScreen extends MainScreen {
		private SimpleList listField;

		public SimpleListScreen() {
			super(Manager.NO_VERTICAL_SCROLL);
			setTitle("Simple List Demo");
			add(new LabelField("Blackberry Team", LabelField.FIELD_HCENTER));
			add(new SeparatorField());
			Manager mainManager = getMainManager();
			mainManager.setMargin(0, 0, 0, 50);

			listField = new SimpleList(mainManager);

			listField.add("Mr.Sushil");// /////////////// i want to open a new
			listField.add("Mr.Anantha");
			listField.add("Mr.Himanshu");

			listField.setCommand(new CommandHandler() {

				public void execute(ReadOnlyCommandMetadata metadata,
						Object context) {

					if (listField.getFocusRow() == 0) {
						UiApplication.getUiApplication().pushScreen(new P());
					}

				}
			}, null, null);

		}

		
	}

}

 No need of FieldChangeListener interface

 

Run it and if you think you got the required solution just set this thread as SOLVED

warm regards
Mohammed Aziz
Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: ListField in Blackberry---open new screen after click listfield items

Thanks so much its working .

 

Tell me one thing 

can i open more screen with left listField items.

Please use plain text.
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: ListField in Blackberry---open new screen after click listfield items

ya i can open more with your solution with just

 

else if(listField.getFocusRow()==1)
{
UiApplication.getUiApplication().pushScreen(new Hello());
}
else
{

}

Please use plain text.
Developer
MohammedAziz
Posts: 139
Registered: ‎02-23-2012
My Device: Blackberry bold
My Carrier: Vodafone India

Re: ListField in Blackberry---open new screen after click listfield items

Yes, you can

if (listField.getFocusRow() == 0) {
UiApplication.getUiApplication().pushScreen(new P());
}
just change the condition in IF and you can set command on left list elements. Use Switch case like this

int index = listField.getFocusRow();

switch (index) {
case 0:

UiApplication.getUiApplication().pushScreen(new P());

break;

case 1:

Dialog.alert("You Clicked on index : " + index);

break;
case 2:

UiApplication.getUiApplication()
.pushScreen(new next());

break;

}
warm regards
Mohammed Aziz
Please use plain text.