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: 207
Registered: ‎07-31-2009
My Device: Not Specified

Dynamic Table row addition-Problem

[ Edited ]

 

Hi,

I need to add rows to a table dynamically on button click. I have managed to do this with the following code. But the thing is after adding more than three rows the add button moves down and am no longer able to see it. But am able to click and create new rows cos i know its there. Am not able to scroll to the button and see it on the screen. And when a new row is added am not able to see that also unless i scroll up atleast once. I have used the code which was given to demonstrate the use of an editable table at :

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/...

 

Morover i am also required to iterate through all the rows that were created after addition of a certain no of rows. Any ideas on that !!??

 

 

The code that i ve is as follows:

 

import java.util.Date;

 

import javax.microedition.lcdui.Choice;

import javax.microedition.lcdui.ChoiceGroup;

import javax.microedition.lcdui.DateField;

 

import net.rim.device.api.i18n.DateFormat;

import net.rim.device.api.system.*;

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

import net.rim.device.api.ui.component.*;

import net.rim.device.api.ui.container.*;

//main table class that provides constructor to display UI components

class Table extends UiApplication implements TrackwheelListener, KeyListener

{

   //private members of table class

   private VerticalFieldManager mainVerticalManager;

   private VerticalFieldManager column1;

   private VerticalFieldManager column1row2;

 

   private HorizontalFieldManager mainHorizontalManager;

   private HorizontalFieldManager secondHorizontalManager;

   //title to be displayed

   private String title = "Submit ";

   private ObjectChoiceField choiceField;

   //main function that serves as the entry point for the BlackBerry

   //application

   //calls the Table constructor to display the UI components

   public static void main(String [] args)

   {

       Table app = new Table();

       app.enterEventDispatcher();

   }

   //Table constructor

   public Table()

   {

       //instance of FullScreen (extends Screen) to display all the UI

       //components on

       FullScreen tableScreen = new FullScreen();

       mainVerticalManager = new VerticalFieldManager();

       //main vertical manager to display the

       //the title, separator, and main

       //horizontal manager

       mainHorizontalManager = new HorizontalFieldManager(Field.USE_ALL_WIDTH|Manager.HORIZONTAL_SCROLL|Manager.VERTICAL_SCROLL );

       //main horizontal

       secondHorizontalManager = new HorizontalFieldManager(Field.USE_ALL_WIDTH|Manager.HORIZONTAL_SCROLL|Manager.VERTICAL_SCROLL );

       //secondary manager

       column1 = new VerticalFieldManager(Manager.VERTICAL_SCROLL);

       //secondary vertical manager to be displayed within the

       //main horizontal manager

       column1row2=new VerticalFieldManager(Manager.VERTICAL_SCROLL);

 

       mainVerticalManager.add(new LabelField

       (

             title,

             LabelField.NON_FOCUSABLE

           | LabelField.ELLIPSIS

           | LabelField.USE_ALL_WIDTH

       ));

       //add the separator field to the main vertical manager

       mainVerticalManager.add(new SeparatorField());

 

 

       FieldChangeListener changed= new FieldChangeListener()

    {

     

public void fieldChanged(Field field , int context)

{

try{

 

       String days[] = {"Monday", "Tuesday", "Wednesday","Thursday","Friday"};

       choiceField = new ObjectChoiceField("Day : ", days,0, choiceField.FIELD_LEFT);

       column1.add(choiceField);

 

 

 

       String choices[] = {"Choice1", "Choice2", "Choice3"};

       choiceField = new ObjectChoiceField("S ", choices,0, choiceField.FIELD_LEFT);

 

       column1.add(choiceField);

 

       column1.add(new CheckboxField

       ("label",

       false,

       CheckboxField.EDITABLE

       ));

       column1.add(new SeparatorField());

 

 

 

}

catch (Exception e)

{

Dialog.alert(e.toString());

}

finally

{

//

}

}

    };

 

    mainVerticalManager.add(mainHorizontalManager);

    mainHorizontalManager.add(column1);

 

         ButtonField Add = new ButtonField("Add");

 

 

       // Column 1 Row2 

 

       column1row2.add(Add);

 

 

       //Add column1row2 to second horizontal manager 

       secondHorizontalManager.add(column1row2);

       Add.setChangeListener(changed);

 

       //add the main vertical manager to the screen

       mainVerticalManager.add(secondHorizontalManager);

 

       tableScreen.add(mainVerticalManager);

       //add key  listeners to the screen

      tableScreen.addKeyListener(this);

 

       //push the screen onto the UI stack

       pushScreen(tableScreen);

   }

   //function to make the menu with the default Close menu item visible

   public void makeMenu(Menu menu)

   {

       menu.add("Close", null, 100);

 

   }

   //function to tell the application what do in the event that the Close menu

   //item is selected

   public void menuSelected(int id)

   {

      if (id == 100)

      {

          int index = choiceField.getSelectedIndex();

          Dialog.alert((String) choiceField.getChoice(index));

      System.exit(0);

 

      }

   }

   //function to tell the applciation what to do when the trackwheel is clicked

   public boolean trackwheelClick(int status, int time)

   {

       Menu appMenu = new Menu();

       //create an instance of menu

       makeMenu(appMenu);

       //make the menu and pass it the instance of menu

       appMenu.show();

       //show the menu

       menuSelected(appMenu.getSelectedId());

       //get the selected menu ID

       return true;

       //return true to indicate the trackwheel was clicked

   }

   //function to tell the application what to do when a key is pressed

   public boolean keyChar(char key, int status, int time)

   {

       switch (key) {

           case Characters.ESCAPE:

               //if the key pressed is one of the escape characters,

               //exit the application

                System.exit(0);

                break;

       }

       return true;

       //return true to indicate that a key was pressed

   }

   //return false in all these cases because we want the application to do

   //nothing

   //special in the case of these trackwheel and keyboard events

   public boolean keyDown(int keycode, int time)

   { return false; }

   public boolean keyRepeat(int keycode, int time)

   { return false; }

   public boolean keyStatus(int keycode, int time)

   { return false; }

   public boolean keyUp(int keycode, int time)

   { return false; }

   public boolean trackwheelUnclick(int status, int time)

   { return false; }

   public boolean trackwheelRoll(int amount, int status, int time)

   { return false; }

}


 

Message Edited by nirmalsat on 08-25-2009 11:03 AM
Message Edited by nirmalsat on 08-25-2009 11:03 AM
Message Edited by nirmalsat on 08-25-2009 11:07 AM
Message Edited by nirmalsat on 08-25-2009 11:08 AM
------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Dynamic Table row addition-Problem

Can you format the code and repost it. Also write down what exactly is your problem.

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 207
Registered: ‎07-31-2009
My Device: Not Specified

Re: Dynamic Table row addition-Problem

[ Edited ]

Sorry about that.. It jus got messed up..

 

I have edited the code and have  marked the important parts of the code in bold.

Message Edited by nirmalsat on 08-25-2009 11:56 AM
------------------------------------------------------------------------------------------------------------------------
Click the Kudos! badge on left side of the message , if you are happy with a solution given by a user. When you do so, you are saying thanks to its author.
Mark a reply as a solution , if you think your question has been answered.
To mark a message as a solution: Click "Accept as solution" icon on the reply.
BlackBerry Development Advisor
Posts: 15,814
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Dynamic Table row addition-Problem

Note that scrolling is only enabled if there are focusable fields outside of the visible area that can be selected.  To allow for scrolling through your LabelFields you can either allow them to be focusable or add focusable NullFields, which are not visible to the user but do allow for scrolling.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.