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

How to create this Table or list

Hello all,

                i need to develope a screen with

               

                CheckBox image  , Id , Time ,and  Name like in this  screen shot.9810.jpg

       

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: How to create this Table or list

Can not see ur image....but i think what u r trying to achive is a list of rows containg checkbox,id,time and name...

 

ListField will be the best thing to implement something like this.

 

See the sample BB applications.

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: How to create this Table or list

see this

 

http://supportforums.blackberry.com/t5/Java-Development/Simple-ListField-example/m-p/426809#M84251

 

There are many exapmles of listfields in the forum, do a search

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: How to create this Table or list

Thanks for reply,

 

But This link can not help me bocoz it is just simple list  .....I need design like my posted image.

which arrange fields in a row like

 

{image,textbox,textbox,textbox}------in a single row.

can u help me in this  question...what i need to do.

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: How to create this Table or list

Actully i found a Bb sample code ..i modified it but some problem i getting .when i wanted to write a full name like "Mr.Ramesh"..the Ramesh goes to next line

why it happen...and i want to reduce the space between Columns 

 

 

Reduce space bet

ween checkbox and id.

New Picture.png

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: How to create this Table or list

Code is:.

/*
 * TableAdapterScreen.java
 *
 * Copyright © 1998-2011 Research In Motion Ltd.
 * 
 * Note: For the sake of simplicity, this sample application may not leverage
 * resource bundles and resource strings.  However, it is STRONGLY recommended
 * that application developers make use of the localization features available
 * within the BlackBerry development platform to ensure a seamless application
 * experience across a variety of languages and geographies.  For more information
 * on localizing your application, please refer to the BlackBerry Java Development
 * Environment Development Guide associated with this release.
 */

package com.rim.samples.device.ui.tableandlistdemo;

import java.util.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.table.*;
import java.lang.Thread;
import net.rim.device.api.ui.*;



public class TableAdapterScreen extends UiApplication
{
   
 public static void main( String args[])
 { 
   TableAdapterScreen tt = new TableAdapterScreen();
   tt.enterEventDispatcher(); 
      
  }
  
   public TableAdapterScreen()
    {
     pushScreen(new TableAdapterScreen1());
     }
 }

  class TableAdapterScreen1 extends MainScreen
{
    private DeviceTableModelAdapter _tableModel;
    private Vector _devices;

    private static final int NUM_ROWS =1;
    private static final int ROW_HEIGHT = 50;
    private static final int NUM_COLUMNS = 5;


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

        setTitle("List");

        add(new LabelField("CaseList", LabelField.FIELD_HCENTER));
        add(new SeparatorField());

        _devices = new Vector();

        _tableModel = new DeviceTableModelAdapter();

        // Add data to adapter
        
        Bitmap bitmap = Bitmap.getBitmapResource("checkbox1.png");
        String id ="15421";
        String time = "05:45";
        String name = "Mr.Ramesh";
        String widthsetter = " ";
      
               {
       /* while(deviceData.hasMoreTokens())
        {
            String modelNumber = deviceData.nextToken().trim();
            String modelName = deviceData.nextToken().trim();
            deviceData.nextToken(); // Consume unwanted input
            Bitmap bitmap = Bitmap.getBitmapResource("checkbox.png");
            deviceData.nextToken();
            deviceData.nextToken();

            Object[] row = {modelName, modelNumber, bitmap};

            _tableModel.addRow(row);
              Thread.sleep(1000);
        }*/
     
        Object[] row ={bitmap,id,time,name,widthsetter};
        _tableModel.addRow(row);
     
        // Set up table view and controller
        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);

        // 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]),new LabelField((String) data[3]),new LabelField((String) data[4])};
                return fields;
            }
        };

        dataTemplate.useFixedHeight(true);

        // 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));
        }

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

        add(tableView);
    }}

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


        /**
         * 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(Bitmap image,String id, String time, String name,String widthsetter)
        {
            _id = id;
            _time = time;
            _name = name;
            _image = image;
            _widthsetter = widthsetter;
        } 


        /**
         * 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 getId()
        {
            return _id;
        }


        public String getTime()
        {
         return _time;
         }
        /**
         * Retrieves the device image
         * 
         * @return The image for the device
         */
        public Bitmap getImage()
        {
            return _image;
      
        }
        
        public String getWidthsetter()
        {
         return _widthsetter;
         }
       
    }

    /**
     * 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( (Bitmap) arrayRow[0],(String) arrayRow[1],(String) arrayRow[2],(String) arrayRow[3],(String) arrayRow[4]));
            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.getId(), device.getTime(),device.getName(),device.getWidthsetter()};
            return row;
        }
    }}

 

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: How to create this Table or list

Can any guide me to how to reduce column size in this tableAdapter

Developer
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold
My Carrier: Vodafone

Re: How to create this Table or list

check the size of the bitmap u r using....i think it is taking lot more space that required.

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

Re: How to create this Table or list

give me a suggestion that can i make focus like listfield in GridFieldManager.

 

answer plz.

 

if yes then How ? guide me.