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
Regular Contributor
Alfredo2828
Posts: 58
Registered: ‎03-23-2011
My Device: 9800

Problem with BlackberryList

Hi,

I'm trying to add an instance of blackberrylist to my mainscreen but I can't. i've tried whith add(), addAll(), pushscreen() and nothing...

Could someone help me? Does someone know some example?

 

Thanks

Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Problem with BlackberryList

[ Edited ]

I think BlackberryList if used in MIDlets only:

 

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Screen
          extended by javax.microedition.lcdui.List
              extended by net.rim.device.api.lcdui.BlackBerryList

 

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Regular Contributor
Alfredo2828
Posts: 58
Registered: ‎03-23-2011
My Device: 9800

Re: Problem with BlackberryList

Yes, you're right...

One thing, do you know some class usefull to add in a same row: an image, some lines of text, some button and that it has some method to know the selected row?

 

Thanks

Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Problem with BlackberryList

Regular Contributor
Alfredo2828
Posts: 58
Registered: ‎03-23-2011
My Device: 9800

Re: Problem with BlackberryList

Thanks, I'm not sure, but, in the Simplelist you can not add any image, any button, just text.

And in the Richlist, there aren't any method to know the selected row...

 

Maybe, the only one that I can use is Tablemodel, Tableview... I don't know...

Developer
dx22
Posts: 402
Registered: ‎11-26-2010
My Device: Torch

Re: Problem with BlackberryList

If you ask me its better to use the tablemodel,tableview approaches(though i didn't examine the code deeply) because you can modify the code to work exactly as you need it. And you won't lose support for devices with older os version.

 

Here is something I found in a doc:

 

 

  • Use the SimpleList class to create a list with text. Use the RichList class to create a display-only list with text and icons. Use the TableView class to create an interactive rich list with text and icons. For more information about creating lists, see the API reference for the BlackBerry® Java® SDK and the BlackBerry Java Application UI Quick Reference Guide.
  •  Use the TableView class to create a table with rows and columns. You can use the GridFieldManager if the number of rows and columns in the table are fixed. For more information about creating tables, see the API reference for the BlackBerry® Java® SDK and the BlackBerry Java Application UI Quick Reference Guide.
  • If the list is long and you want to display the items on separate screens, include Next and Previous buttons at the bottom of the screen. Alternatively, if the list is very long (for example, thousands of items), provide screen numbers instead.
  • If you expect users to move through the items in the list (for example, in a message list or a feed), assign shortcut keys for moving to the next or previous item in the list. Where possible, in English, allow users to press "N" to move to the next item in the list and "P" to move to the previous item in the list.
  • Use the SimpleList class to create a list with text. Use the RichList class to create a display-only list with text andicons. Use the TableView class to create an interactive rich list with text and icons. For more information about creatinglists, see the API reference for the BlackBerry® Java® SDK and the BlackBerry Java Application UI Quick Reference Guide.• Use the TableView class to create a table with rows and columns. You can use the GridFieldManager if the numberof rows and columns in the table are fixed. For more information about creating tables, see the API reference for theBlackBerry® Java® SDK and the BlackBerry Java Application UI Quick Reference Guide.• If the list is long and you want to display the items on separate screens, include Next and Previous buttons at the bottomof the screen. Alternatively, if the list is very long (for example, thousands of items), provide screen numbers instead.• If you expect users to move through the items in the list (for example, in a message list or a feed), assign shortcut keys formoving to the next or previous item in the list. Where possible, in English, allow users to press "N" to move to the next itemin the list and "P" to move to the previous item in the list.

 

----------------------------------------------------------------------
Press the button to give kudos if I helped you :smileyhappy:
Regular Contributor
Alfredo2828
Posts: 58
Registered: ‎03-23-2011
My Device: 9800

Re: Problem with BlackberryList

Thanks, you're right :smileyhappy: I gonna use Tableview

Regular Contributor
Alfredo2828
Posts: 58
Registered: ‎03-23-2011
My Device: 9800

Re: Problem with BlackberryList

Hi, I've used a custom table(by a modified example from eclipse TableAndListDemo->TableAdapterScreen) to do a list of 2 columns but it doesn't work... I don't know what happens...

The code is this:

 

/**
 * A screen demonstrating the use of the Table and List API to display data held
 * in a non-table data structure in table format.
 */
public final class CustomTable2 extends MainScreen
{
    private DeviceTableModelAdapter _tableModel;
    private Vector _devices;
    private TableView tableView;/////

    private static final int NUM_ROWS = 1;
    private static final int ROW_HEIGHT = 100;
    private static final int NUM_COLUMNS = 2;//3;


    /**
     * Creates a new CustomTable2 object
     *
     * @param deviceData Data read from file to be displayed in table
     */
    public CustomTable2()
    {
        super(Manager.NO_VERTICAL_SCROLL);//////////////
        //super(Manager.HORIZONTAL_SCROLL & Manager.HORIZONTAL_SCROLLBAR);

        setTitle("Table Adapter Screen");

        add(new LabelField("BlackBerry Devices", LabelField.FIELD_HCENTER));
        add(new SeparatorField());
        ////////
        ButtonField butRow = new ButtonField("what clicked row?");
        add(butRow);
        ////////

        _devices = new Vector();

        _tableModel = new DeviceTableModelAdapter();

        //////////////
        StringTokenizer deviceData = getStringTokenizer();
        //////////////
        
        // Add data to adapter
        while(deviceData.hasMoreTokens())
        {
            String modelNumber = deviceData.nextToken().trim();
            String modelName = deviceData.nextToken().trim();
            deviceData.nextToken(); // Consume unwanted input
            Bitmap bitmap = Bitmap.getBitmapResource(modelNumber + ".png");
            deviceData.nextToken();
            deviceData.nextToken();

            Object[] row = {modelName + "adios\nadios2...\nadiosadiosadiosadiosadiosadiosadiosadiosadiosadiosadiosadiosadiosadiosadiosadios", modelNumber + "\nhola...\nholaAgain...holaholaholaholaholaholaholaholaholaholaholaholaholaholaholaholahola", bitmap};//////////

            _tableModel.addRow(row);
        }

        // Set up table view and controller
        tableView = new TableView(_tableModel);
        ////////TableView tableView = new TableView(_tableModel);
        tableView.setDataTemplateFocus(BackgroundFactory.createLinearGradientBackground(Color.WHITE, Color.WHITE, Color.BLUEVIOLET, Color.BLUEVIOLET));
        TableController tableController = new TableController(_tableModel, tableView);
        tableController.setFocusPolicy(TableController.ROW_FOCUS);
        tableView.setController(tableController);
        /////////////
        butRow.setCommand(new Command(new CommandHandler()
        {         
            public void execute(ReadOnlyCommandMetadata metadata, Object context)
            {
                Dialog.alert(String.valueOf(tableView.getRowNumberWithFocus()));
            }           
        }));
        ////////////
        
        // Specify a simple data template for displaying 3 columns
        DataTemplate dataTemplate = new DataTemplate(tableView, NUM_ROWS, NUM_COLUMNS)
        {
            /**
             * @see DataTemplate#getDataFields(int)
             */
            public Field[] getDataFields(int modelRowIndex)
            {
                Object[] data = (Object[]) (_tableModel.getRow(modelRowIndex));
                ////Field[] fields = {new BitmapField((Bitmap) data[0]), new LabelField((String) data[1])/*, new LabelField((String) data[2])*/};/////
                Field[] fields = {new BitmapField((Bitmap) data[0]), new LabelField((String) data[1])/*, new LabelField((String) data[2])*/};////////////////
                return fields;
            }
        };

        ////dataTemplate.useFixedHeight(true);
        dataTemplate.useFixedHeight(false);/////

        // Define regions and row height
        dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));
        /*for(int i = 0; i < NUM_COLUMNS; i++)
        {
            dataTemplate.createRegion(new XYRect(i, 0, 1, 1));
            dataTemplate.setColumnProperties(i, new TemplateColumnProperties(Display.getWidth() / NUM_COLUMNS));
        }*/
        /////////////
        dataTemplate.createRegion(new XYRect(0, 0, 1, 1));
        dataTemplate.setColumnProperties(0, new TemplateColumnProperties(Display.getWidth() / NUM_COLUMNS));////////
        dataTemplate.createRegion(new XYRect(1, 0, 1, 1));
        dataTemplate.setColumnProperties(1, new TemplateColumnProperties(Display.getWidth() / NUM_COLUMNS));///////////////
        //dataTemplate.createRegion(new XYRect(2, 0, 1, 1));
        //dataTemplate.setColumnProperties(2, new TemplateColumnProperties(Display.getWidth() / NUM_COLUMNS));
        /////////////

        // Apply the template to the view
        tableView.setDataTemplate(dataTemplate);

        add(tableView);
    }
    
    ////////////
    /**
     * Retrieves data from resource text file and stores contents in a
     * string tokenizer
     *
     * @return A string tokenizer containing data from file
     */
    private StringTokenizer getStringTokenizer()
    {

        InputStream stream = getClass().getResourceAsStream("/resources/blackberry.txt");
        LineReader lineReader = new LineReader(stream);
        final StringBuffer buffer = new StringBuffer();

        while(true)
        {
            try
            {
                buffer.append(new String(lineReader.readLine()));
                buffer.append("\n");
            }
            catch(EOFException eof)
            {
                // We've reached the end of the file
                break;
            }
            catch(final IOException ioe)
            {
                UiApplication.getUiApplication().invokeLater(new Runnable()
                {
                    public void run()
                    {
                        Dialog.alert("LineReader#readLine() threw " + ioe.toString());
                    }
                });
            }
        }

        String data = buffer.toString();

        data = data.replace('\r', ',');
        data = data.replace('\n', ',');

        return new StringTokenizer(data);
    }
    ////////////

    /**
     * A class encapsulating name, model number and <code>Bitmap</code> image
     * for a BlackBerry Device.
     */
    private final static class BlackBerryDevice
    {
        private String _name;
        private String _model;
        private Bitmap _image;


        /**
         * Creates a new BlackBerryDevice object
         *
         * @param name The name of the device
         * @param model The model number of the device
         * @param image An image of the device
         */
        BlackBerryDevice(String name, String model, Bitmap image)
        {
            _name = name;
            _model = model;
            _image = image;
        }


        /**
         * Retrieves the device name
         *
         * @return The name of the device
         */
        public String getName()
        {
            return _name;
        }


        /**
         * Retrieves the device model
         *
         * @return The model of the device
         */
        public String getModel()
        {
            return _model;
        }


        /**
         * Retrieves the device image
         *
         * @return The image for the device
         */
        public Bitmap getImage()
        {
            return _image;
        }
        
        //////
        public String getAllmenosimagelineaalinea(){
            return (_model + "\n" + _name);
        }
        //////
    }

    /**
     * Adapter for displaying BlackBerryDevice objects in a table format
     */
    private class DeviceTableModelAdapter extends TableModelAdapter
    {
        /**
         * @see net.rim.device.api.ui.component.table.TableModelAdapter#getNumberOfRows()
         */
        public int getNumberOfRows()
        {
            return _devices.size();
        }


        /**
         * @see net.rim.device.api.ui.component.table.TableModelAdapter#getNumberOfColumns()
         */
        public int getNumberOfColumns()
        {
            return NUM_COLUMNS;
        }


        /**
         * @see net.rim.device.api.ui.component.table.TableModelAdapter#doAddRow(Object)
         */
        protected boolean doAddRow(Object row)
        {
            Object[] arrayRow = (Object[]) row;
            _devices.addElement(new BlackBerryDevice((String) arrayRow[0], (String) arrayRow[1], (Bitmap) arrayRow[2]));
            return true;
        }


        /**
         * @see net.rim.device.api.ui.component.table.TableModelAdapter#doGetRow(int)
         */
        protected Object doGetRow(int index)
        {
            BlackBerryDevice device = (BlackBerryDevice) _devices.elementAt(index);
            ///Object[] row = {device.getImage(), device.getModel(), device.getName()};
            Object[] row = {device.getImage(), device.getAllmenosimagelineaalinea()};////////
            return row;
        }
    }
}