how to create multiple VerticalFieldManager dynamically Blackberry - java

I've been struggling to create multiple VerticalFieldManager dynamically on Blackberry. Each subManager will show different data to the user. And each subManager will have a different position on the screen. So i created a class which has a "mainManager" and another class which creates the "submanagers" then i call mainManager.add(new TheClassExtendingVerticalFieldManager); to add the subManagers to the mainManager. The problem is that i only get one subManager instead of three. I'm using padding to separate the managers. Here's the code im using. Please guide me in the right direction, it would be much appreciated.
The class that creates the submanager
public class ProgramListView extends VerticalFieldManager{
private VerticalFieldManager subManager;
private int _height;
public ProgramListView(int height){
this._height = height;
// subManager = new VerticalFieldManager(
// Manager.NO_HORIZONTAL_SCROLL | Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR |
// Manager.NO_HORIZONTAL_SCROLLBAR | Manager.USE_ALL_WIDTH)
//
// {
//
//
// };
}
public int get_height() {
return _height;
}
public void set_height(int _height) {
this._height = _height;
}
public void setCoordinates(int x, int y){
setPosition(100,140);
}
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = Display.getWidth();
int displayHeight = maxHeight;
this.setPosition(300, 300);
super.sublayout( 40, 40);
setPadding(this.get_height(), 0, 0, 0);
setExtent(displayWidth, this.get_height());
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.BLUE);//blue
graphics.clear();
super.paint(graphics);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
}
The mainManager class
public class ProgramLayout extends MainScreen {
private HorizontalFieldManager mainManager;
private int deviceWidth = Display.getWidth();
private int deviceHeight = Display.getHeight();
private Vector subManagers;
private int theheight;
public ProgramLayout(){
setToolbar();
subManagers = new Vector();
theheight = 100;
mainManager = new HorizontalFieldManager(Manager.VERTICAL_SCROLL | Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight)
{
int displayWidth = deviceWidth;
int displayHeight = deviceHeight;
super.sublayout( displayWidth, displayHeight);
setExtent(displayWidth, displayHeight);
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
};
for (int i = 0; i < 3; i++) {
theheight = theheight+100;
subManagers.addElement(new ProgramListView(theheight));
}
for (int i = 0; i < subManagers.size(); i++) {
mainManager.add((VerticalFieldManager)subManagers.elementAt(i));
}
this.add(mainManager);
}
Thanks in advance

try this:
for (int i = 0; i < 3; i++) {
theheight = theheight+100;
mainManager.add(new ProgramListView(theheight));
}
this.add(mainManager);

Just to elaborate on what Eugen Martynov pointed out, your mainManager is a HorizontalFieldManager, which means it will lay out child fields in the order that you add() them, horizontally. It automatically handles layout for you, based on the order of calls you make to add().
But, each child is an instance of ProgramListView and returns Display.getWidth() in
getPreferredWidth():
public int getPreferredWidth() {
// TODO Auto-generated method stub
return Display.getWidth();
}
So, the first one takes up the whole screen width, and the next two would have to be to the right of that (but you've already taken up the whole screen width).
Did you want these three ProgramListViews to be stacked vertically? Then, mainManager should just be changed to a VerticalFieldManager. With a VerticalFieldManager, calling add() for three different ProgramListView child fields will automatically lay them out vertically.

Related

.setLocation in thread not calling repaint in seperate object (java)

--WORKING ON A SHORTER VERSION OF THE QUESTION--
So, this is someting I can't really find that much information on online.
I am making a game together with my friend and we came accross a problem when we wanted to move some objects in a thread. We have one object, GroundBlocks, which is working fine and how it is supposed to.
Then we have the other object, Obstacles, that uses the same "method" of printing and processing but doesn't show up.
I did some troubleshooting myself and I noticed that the paintComponent block in Obstacles isn't beeing called by the .setLocation we added in the thread.
As I mentioned, I didn't find a whole lot online when searching myself but through testing, I know the numbers are correct but it is just not showing.
Any ideas on what the issue might be with the .setLocation not working?
--Relevant code from the thread class--
// Creating objects
public static GroundBlocks[] ground = {new GroundBlocks(), new GroundBlocks(), new GroundBlocks()};
public static Obstacles[] obstacle = {new Obstacles(), new Obstacles(), new Obstacles(), new Obstacles(), new Obstacles()};
// Creating block dimensions
final int GROUND_HEIGHT = resY - GroundBlocks.getGroundHeight();
final int GROUND_WIDTH = ground[1].getGroundWidth();
int[] groundX = {0, GROUND_WIDTH, GROUND_WIDTH*2};
final int OBSTACLE_HEIGHT = obstacle[0].getHeight();
final int OBSTACLE_WIDTH = obstacle[0].getWidth();
int[] obstacleX = {newCoord(0), newCoord(0), newCoord(0), newCoord(0), newCoord(0)};
int[] obstacleY = {newCoord(1), newCoord(1), newCoord(1), newCoord(1), newCoord(1)};
// Setting game animation movement
final int MOVEMENT_SPEED = 7;
// Setting timer object with preferred FPS
Timer time = new Timer(Init.getFps(0), this);
public void run() {
System.out.println("A new MainThread has been initiated");
time.start();
// Setting ground block size, starting location and image
for(int i = 0; i < ground.length; i++) {
ground[i].setLocation(groundX[i], GROUND_HEIGHT);
ground[i].setSize(GROUND_WIDTH, GROUND_HEIGHT);
ground[i].setGroundImage(pickRandomGroundImage());
}
// Setting background image for obstacles
for (int i = 0; i < obstacle.length; i++) {
obstacle[i].setSize(OBSTACLE_WIDTH, OBSTACLE_HEIGHT);
obstacle[i].setLocation(obstacleX[i], obstacleY[i]);
obstacle[i].setObstacleImage(img5);
// System.out.println(obstacle[i].getLocation());
}
}
#Override
public void actionPerformed(ActionEvent arg0) {
for(int i = 0; i < ground.length; i++) {
// Respawning ground block
if(groundX[i] <= -resX) {
groundX[i] = GROUND_WIDTH*2 - MOVEMENT_SPEED;
ground[i].setGroundImage(pickRandomGroundImage());
}
// Animating ground block
ground[i].setLocation(groundX[i] -= MOVEMENT_SPEED, GROUND_HEIGHT);
}
for (int i = 0; i < obstacle.length; i++) {
// Resetting obstacle block
if ((obstacleX[i] + OBSTACLE_WIDTH) <= -10) {
obstacleX[i] = newCoord(0);
obstacleY[i] = newCoord(1);
obstacle[i].setObstacleImage(img5);
}
// Animating obstacle block
obstacle[i].setLocation(obstacleX[i] -= MOVEMENT_SPEED, obstacleY[i]);
if (i == 0) {
System.out.println(obstacle[i].getLocation());
}
}
}
--GroundBlocks class--
public class GroundBlocks extends JPanel{
// Declarations
static int resX = Main._init.getResX();
static int resY = Main._init.getResY();
static String font = Main._init.getOurFont();
private static int groundWidth;
private static int groundHeight;
private Image chosenImage;
public GroundBlocks() {
System.out.println("GroundBlock created");
setScaleIndex();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
//Draw image background
g.drawImage(chosenImage, 0, 0, this);
}
// Applying the scaleIndex to the ground objects X and Y dimensions.
// Size changes can be made manually in Init.
public void setScaleIndex() {
groundWidth = (int) (Init.getGroundSize(0) * Init.getScaleIndex());
groundHeight = (int) (Init.getGroundSize(1) * Init.getScaleIndex());
}
public int getGroundWidth() {
return groundWidth;
}
public static int getGroundHeight() {
return groundHeight;
}
public void setGroundImage(Image image) {
chosenImage = image;
}
}
--Obstacles code--
public class Obstacles extends JPanel{
// Declarations
static int resX = Main._init.getResX();
static int resY = Main._init.getResY();
static String font = Main._init.getOurFont();
private static int obstacleHeight;
private static int obstacleWidth;
private Image chosenImage;
public Obstacles() {
System.out.println("New obstacle object created!");
setScaleIndex();
repaint();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
System.out.println("Printed obstacle");
g.drawImage(chosenImage, 0, 0, this);
}
// Applying the scaleIndex to the ground objects X and Y dimensions.
// Size changes can be made manually in Init.
public void setScaleIndex() {
obstacleWidth = (int) (Init.getObstacleSize(0) * Init.getScaleIndex());
obstacleHeight = (int) (Init.getObstacleSize(1) * Init.getScaleIndex());
}
public int getObstacleHeight() {
return obstacleHeight;
}
public int getObstacleWidth() {
return obstacleWidth;
}
public void setObstacleImage(Image image) {
chosenImage = image;
}
}

Testing an imageeffect using a bufferedimage

Ive made a class that applies a tiling effect to a bufferedimage and i have to make a JUnit test on the class but im unsure of what to test and how i can test it.
I know i have to use assert and the likes but im not sure how.
I was thinking it would be something with the image being divided in 4.
public class TilesAction extends AbstractSelectedAction {
public static String ID = "edit.Tiles";
SVGImageFigure image;
public TilesAction(DrawingEditor editor) {
super(editor);
}
#Override
public void actionPerformed(ActionEvent ae) {
final DrawingView view = getView();
final LinkedList<Figure> figures = new LinkedList<Figure>(view.getSelectedFigures());
final Figure figure = figures.getFirst();
tiling(figure);
fireUndoableEditHappened(new AbstractUndoableEdit() {
#Override
public String getPresentationName() {
return labels.getTextProperty(ID);
}
#Override
public void redo() throws CannotRedoException {
super.redo();
}
#Override
public void undo() throws CannotUndoException {
super.undo();
}
});
}
private void tiling(Figure figure) {
image = (SVGImageFigure) figure;
BufferedImage tilingImage = image.getBufferedImage();
Graphics g = tilingImage.getGraphics();
DefaultDrawingView ddv = new DefaultDrawingView();
int width = tilingImage.getWidth() / 4;
int height = tilingImage.getHeight() / 4;
Image scaled = tilingImage.getScaledInstance(width, height, Image.SCALE_SMOOTH);
// Tile the image to fill our area.
for (int x = 0; x < tilingImage.getWidth(); x += width) {
for (int y = 0; y < tilingImage.getHeight(); y += height) {
g.drawImage(scaled, x, y, null);
}
}
g.dispose();
}
}

Duplicate JLabel when setting text [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I don't really have any code to show for the problem I add a JLabel to the JPanel, and I set the text to the mouse's current x/y position while the mouse is moving.
I'd appreciate if anyone could explain why this is happening.
PComponent.java
public class PComponent extends JPanel implements Commons {
private static final long serialVersionUID = -5525789712337277886L;
public PComponent(int x, int y, int width, int height) {
this.setLocation(x, y);
this.setSize(width, height);
}
}
PNode
public class PNode extends PComponent {
public PNode(int x, int y, int width, int height) {
super(x, y, width, height);
this.setOpaque(false);
this.setBorder(BorderFactory.createLineBorder(Color.RED));
}
}
PInterface
public abstract class PInterface extends PComponent implements Resizable {
public PInterface(int x, int y, int width, int height, int nodeW, int nodeH) {
super(x, y, width, height);
this.nodeW = nodeW;
this.nodeH = nodeH;
this.node = new PNode[MAX_NODES];
this.addNodes();
this.registerInterface();
this.pack();
}
private void registerInterface() {
for (int i = 0; i < cachedInterface.length; i++) {
if(cachedInterface[i] == null) {
cachedInterface[i] = this;
break;
}
}
}
private void addNodes() {
int index = 0;
for (int i = 0; i < this.getWidth(); i+=nodeW) {
for (int j = 0; j < this.getHeight(); j+=nodeH) {
PNode node = new PNode(i,j,nodeW,nodeH);
this.add(node);
this.node[index] = node;
index++;
}
}
}
public void writeToNode(String s, int index) {
if(node[index] != null) {
if(node[index].getComponent(0) instanceof JLabel) {
((JLabel) node[index].getComponent(0)).setText(s);
}
}
}
public void writeToNode(String s, int index, int child) {
if(node[index] != null) {
if(node[index].getComponent(child) instanceof JLabel) {
((JLabel) node[index].getComponent(child)).setText(s);
}
}
}
#Override
public void resize() {
}
protected abstract void pack();
protected void createTransparentInterface(int r, int g, int b, int o) {
this.setBackground(new Color(r, g, b, o));
}
public static PInterface[] getCachedInterfaces() {
return cachedInterface;
}
public int getNodeW() {
return nodeW;
}
public void setNodeW(int nodeW) {
this.nodeW = nodeW;
}
public int getNodeH() {
return nodeH;
}
public void setNodeH(int nodeH) {
this.nodeH = nodeH;
}
private static PInterface[] cachedInterface = new PInterface[MAX_INTERFACES];
protected int nodeW;
protected int nodeH;
protected PNode[] node;
}
ClientDetailsInterface
public class ClientDetailsInterface extends PInterface {
public ClientDetailsInterface() {
super(0, 0, 200, 100, 100, 50);
this.createTransparentInterface(255, 0, 0, 100);
}
#Override
protected void pack() {
this.node[0].add(new JLabel("X:"));
this.node[0].add(new JLabel("Y:"));
}
}
Canvas
public class Canvas extends JPanel implements Resizable, Commons, MouseMotionListener {
private static final long serialVersionUID = 8374256772293662258L;
public Canvas() {
this.setBackground(Color.WHITE);
this.setFocusable(true);
this.addMouseMotionListener(this);
this.registerInterfaces();
}
private void registerInterfaces() {
int count = 0;
new ClientDetailsInterface();
for (int i = 0; i < PInterface.getCachedInterfaces().length; i++) {
if (PInterface.getCachedInterfaces()[i] != null) {
this.add(PInterface.getCachedInterfaces()[i]);
count++;
}
}
System.out.println("Loaded: " + count + " interfaces!");
}
#Override
public void resize() {
// TODO add resizing code
}
#Override
public void mouseDragged(MouseEvent arg0) {
}
#Override
public void mouseMoved(MouseEvent mouse) {
PInterface.getCachedInterfaces()[0].writeToNode("X:" + mouse.getX(), 0,0);
PInterface.getCachedInterfaces()[0].writeToNode("Y:" + mouse.getY(), 0,1);
}
}
new screenshot
http://prntscr.com/6dp6rd
Sounds like you are doing custom painting somewhere and you forgot to invoke:
super.paintComponent(g);
to make sure the background is cleared before you do your custom painting.
This of course assumes you are overriding the paintComponent() method. If you are overriding paint(...), don't. Custom painting is done by overriding the paintComponent(...) method.
If you need more help then post your SSCCE because the problem is with your code and we can't tell what you code looks like from a picture.
Edit:
Don't override getX() and getY(). Those are methods of the component class used for painting components at a specific location.
Final Edit:
Take a look at Backgrounds With Transparency for the problem and the solution.

centrally two button not looking good blackberry

I am developing one app in which I want to create two buttons. These buttons should be center aligned custom buttons with bitmap fill backgrounds. Each should also contain text that is centered in that button.
The problem is that those two buttons are not set properly. The second button is gone behind the first and its bitmap height is also decreased compared to the first button.
For both custom buttons I have the same CustomButton class.
Here is code:
CustomButtonField aboutM1 = new CustomButtonField(0,"About G1",registerbg,registerbg,Field.FOCUSABLE,0x324F85);
add(new RichTextField(Field.NON_FOCUSABLE));
// CustomButtonField2 ForgotPass = new CustomButtonField2("Forgot Password?",0x324F85);
CustomButtonField ForgotPass = new CustomButtonField(0,"Forgot Password?",registerbg,registerbg,Field.FOCUSABLE,0x324F85);
add(new RichTextField(Field.NON_FOCUSABLE));
VerticalFieldManager bottomVFM = new VerticalFieldManager(USE_ALL_WIDTH);
HorizontalFieldManager bottomHFM = new HorizontalFieldManager(FIELD_HCENTER);
bottomHFM.add(aboutM1);
bottomHFM.add(ForgotPass);
bottomVFM.add(bottomHFM);
add(bottomVFM);
Custom Button:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.*;
public class CustomButtonField extends Field
{
Bitmap Unfocus_img, Focus_img, current_pic;
int width;
String text;
Font font;
int custColor;
CustomButtonField(int width, String text, Bitmap onFocus, Bitmap onUnfocus, long style,int custColor)
{
super(style);
Unfocus_img = onUnfocus;
Focus_img = onFocus;
current_pic = onFocus;
this.text = text;
this.width = width;
this.custColor = custColor;
}
protected void layout(int width, int height)
{
setExtent(current_pic.getWidth(), current_pic.getHeight());
}
protected void paint(Graphics graphics)
{
try
{
FontFamily fntFamily = FontFamily.forName("BBAlpha Sans");
font = fntFamily.getFont(Font.BOLD,20);
}
catch(Exception e)
{
font = Font.getDefault();
}
graphics.setFont(font);
graphics.setColor(custColor);
int xText = (getWidth() - font.getAdvance(text)) / 2;
int yText = (getHeight() - font.getHeight()) / 2;
graphics.drawBitmap(0, 0, current_pic.getWidth(), current_pic.getHeight(), current_pic , 0 , 0);
graphics.drawText(text, xText, yText);
/* graphics.drawBitmap(0, 0, current_pic.getWidth(), current_pic.getHeight(), current_pic , 0 , 0);
graphics.drawText(text, width , 7);*/
graphics.setDrawingStyle(Graphics.HCENTER | Graphics.VCENTER, true);
}
protected void onFocus(int direction)
{
super.onFocus(direction);
current_pic = Unfocus_img;
this.invalidate();
}
protected void drawFocus(Graphics graphics, boolean on)
{
}
protected void onUnfocus()
{
super.onUnfocus();
current_pic = Focus_img;
invalidate();
}
public boolean isFocusable() {
return true;
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
}
The code you used is correct , the only drawback is that you are centering your text according to your bitmap width & text length is more than bitmap width .
You may need to change your approach .
Have a look on Blackberry UI samples in this below URL & check for EmbossedButtonField Demo
https://github.com/blackberry/Samples-for-Java
Its a good approach to create a custom button , once we are not sure by the button label length.

Set position in customized list field in Blackberry?

I want three list field items to be displayed, from bottom to top. I am able to display three list field items, but they display from top to bottom. I have tried setting the position, but it isn't working.
import java.util.Vector;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.ContextMenu;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.Arrays;
import net.rim.device.api.ui.component.ListField;
/**
* #author Jason Emerick
*/
public class TaskListField extends UiApplication
{
//statics ------------------------------------------------------------------
public static void main(String[] args)
{
TaskListField theApp = new TaskListField();
theApp.enterEventDispatcher();
}
public TaskListField()
{
pushScreen(new TaskList());
}
}
/*class List extends FullScreen {
TaskList tl;
List(){
super();
TaskList tl=new TaskList();
}
}*/
class TaskList extends MainScreen implements ListFieldCallback {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
private Bitmap p3;
String Task;
ListField listnew=new ListField();
public TaskList() {
super();
listnew.setRowHeight(50);
//setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
listnew.setCallback(this);
p1 = Bitmap.getBitmapResource("1.png");
p2 = Bitmap.getBitmapResource("2.png");
p3 = Bitmap.getBitmapResource("3.png");
rows = new Vector();
for (int x = 0; x < 3; x++) {
TableRowManager row = new TableRowManager();
if (x== 0) {
Task="On Air Now";
}
if (x== 1) {
Task="Music Channel";
}
if (x==2) {
Task="News Channel";
}
// SET THE PRIORITY BITMAP FIELD
// if high priority, display p1 bitmap
if (x % 2 == 0) {
row.add(new BitmapField(p1));
}
// if priority is 2, set p2 bitmap
else if (x % 3 == 0) {
row.add(new BitmapField(p2));
}
// if priority is 3, set p3 bitmap
else {
row.add(new BitmapField(p3));
}
// SET THE TASK NAME LABELFIELD
// if overdue, bold/underline
LabelField task = new LabelField(Task,
DrawStyle.ELLIPSIS);
// if due today, bold
if (x % 2 == 0) {
task.setFont(Font.getDefault().derive(
Font.BOLD));
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
}
row.add(task);
LabelField task1 = new LabelField("Now Playing" + String.valueOf(x),
DrawStyle.ELLIPSIS);
// if due today, bold
/* if (x % 2 == 0) {
task.setFont(Font.getDefault().derive(
Font.BOLD));
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
}*/
Font myFont = Font.getDefault().derive(Font.PLAIN, 12);
task1.setFont(myFont);
row.add(task1);
// SET THE DUE DATE/TIME
row.add(new LabelField("",
DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
| DrawStyle.RIGHT) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
rows.addElement(row);
}
listnew.setSize(rows.size());
this.add(listnew);
}
// ListFieldCallback Implementation
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
//TaskList list =(TaskListField) listnew;
TableRowManager rowManager = (TableRowManager)rows
.elementAt(index);
rowManager.drawRow(g, 0, y, width, listnew.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
// Causes the fields within this row manager to be layed out then
// painted.
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(0, 1);
// Place this row manager within its enclosing list.
setPosition(x,y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
g.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
// Arrages this manager's controlled fields from left to right within
// the enclosing table's columns.
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
// start with the Bitmap Field of the priority icon
/* Field field = getField(0);
layoutChild(field, 0, 0);
setPositionChild(field, 150, 300);*/
// set the task name label field
/* field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
// set the list name label field
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);*/
// set the due time name label field
/* field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field,4,340);*/
/* layoutChild(listnew, preferredWidth, fontHeight);
setPositionChild(listnew, 3, 396);*/
setExtent(360, 480);
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return getWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return listnew.getRowHeight();
}
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return null;
}
public int getPreferredWidth(ListField listField) {
// TODO Auto-generated method stub
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
}
What do I need to fix to make it work as I want?
My guess is you want to know how to change the focus to item 3 in your listfield
So the answer is:
listnew.setSelectedIndex(2);

Categories

Resources