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
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: can we add many Fields in ListField

rabiray, what you write is incorrect, you cannot add a checkboxfield to a listfield.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
rabiray
Posts: 141
Registered: ‎07-13-2011
My Device: BB Bold

Re: can we add many Fields in ListField

Hi Simon,

 

I am sure u can...have u tried adding one....

 

I have done a lot of listField development in my current role which has got CheckBoxField  inside a ListField.

 

Regards

Rabi Ray

 

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

Re: can we add many Fields in ListField

Rabi i also not able to add checkbox in this table..

I ll post code as well as image .when image visible to u give ans.

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

Re: can we add many Fields in ListField

/*
 * 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 = 60;
    private static final int NUM_COLUMNS = 4;
    private static  Bitmap bitmap,bitmap2;
    // private static  BitmapField btfield ;


    /**
     * 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.getBitmapResource("checkbox1.png");
        final String[] id = new String[]{"15445","45441","87998","11211","78745"};
        final String[] time = new String[]{"05:30","06:50","04:21","11:20","06:12"}; 
        final String[]  name = new String []{"Rajkumar","Himanshu","Rahul","Pitam","FFFFF"};
       
        Thread th = new Thread()
        {
       
            public void run()
            {
                 try
        {
        for(int i=0;i<5;i++)
        {
          
             bitmap = Bitmap.getBitmapResource("checkbox1.png");
             Object[] row = {bitmap,id[i],time[i],name[i]};
           _tableModel.addRow(row);
             Thread.sleep(1000);
        }}
        catch(Exception n)
        {
        
        }   
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                }});
           }
           };
               
           th.start();
       /* 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);
        }*/
     
        
     
        // 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])};
                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);
    }
    
   BitmapField btfield = new BitmapField(bitmap,BitmapField.FOCUSABLE)
    {
    public boolean navigationClick(int status,int content)
    { 
      bitmap = Bitmap.getBitmapResource("checkcheckBox1.png");
      
            
     return true;   
     }};

    /**
     * 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;


        /**
         * 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)
        {
           _id  = id;
           _time = time;
           _name = name;
            _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 getId()
        {
            return _id;
        }


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

    /**
     * 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]));
            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()};
            return row;
        }
    }}

 

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

Re: can we add many Fields in ListField

Hi

 

I cant see any list field u have used in ur code../

 

I was talking about ListField.... and drawRow Method.

 

Regards

Rabi

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

Re: can we add many Fields in ListField

New Picture.png

This is image if u remember..in last discussion u suggested that i should check image size ..i did that its nothing its few pix...then the diffrence between Ist col and sec col is too much .and not able to reduceit.

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

Re: can we add many Fields in ListField

Hi Himanshu

 

You are using TableView to display your data, and if u see ur code closely at line

This code set the column with equally same for all the columns.

 

Using this way Table columns are divided equal width, so i dnt think there is any way to reduce this.

 

As i have developed my app in Version5.0 where there is no TableView  present and I have to do this in a listfield, where it is possible to add components as required positions.

 

dataTemplate.setColumnProperties(i, new TemplateColumnProperties(Display.getWidth()/NUM_COLUMNS));
Trusted Contributor
Himanshu_berry
Posts: 138
Registered: ‎04-19-2012
My Device: No

Re: can we add many Fields in ListField

can u post code like to add component as we want position in listfield

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

Re: can we add many Fields in ListField

Will try to find some time ......to do this