BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-12-2010, 03:37 AM   #1
Alatar
New Member
 
Join Date: Jun 2010
Model: 7100T
PIN: N/A
Carrier: Qwest
Posts: 2
Default ListField Questions

Please Login to Remove!

Hi everyone,

I'm just starting to learn Blackberry development, so sorry if this is a stupid question. I'm following the code samples listed in JDE 4.3.0 Development guide, and I was wondering how to select an item from the list.

I've gotten the lsit to display properly, but I have no idea how to select an item. Also, when the item is selected, how would I clear the screen to draw something completely new?

Thanks
Offline  
Old 07-12-2010, 03:49 AM   #2
pravipravi
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Default

Please find the custom list field below. Use drawListrow for drawing the contents.

Code:
/*
 * GLClubsListField.java
 *
 * © MOPL, 2003-2008
 * Confidential and proprietary.
 */

package customfields;

import java.util.Enumeration;
import java.util.Vector;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;

/**
 * 
 * @author Praveen.
 * @version 1.0
 */

public class GLClubsListField extends ListField implements ListFieldCallback {
    private Vector _listData;
    
    public GLClubsListField (Vector data)  {
        _listData = data;
        setSize(_listData.size());
        setSearchable(true);
        setCallback(this);
        setRowHeight(Font.getDefault().getHeight() + 12);
    }
    /*
    protected void drawFocus (Graphics graphics, boolean on) {  
        XYRect focusRect = new XYRect();
        
        int offset = 100;
        
        if (Graphics.getScreenHeight() > 240) {
            offset = 150;
        }
        
        graphics.setGlobalAlpha(150); 
        graphics.setColor(Color.BLUE);
        getFocusRect(focusRect);
        drawHighlightRegion(graphics, HIGHLIGHT_FOCUS, true, focusRect.x, focusRect.y, 
                                                            focusRect.width, focusRect.height);            
    }*/
    
    protected void drawFocus (Graphics graphics, boolean on) {
            XYRect rect = new XYRect();
            graphics.setGlobalAlpha(150); 
            graphics.setColor(Color.BLUE);
            getFocusRect(rect);
            drawHighlightRegion(graphics,HIGHLIGHT_FOCUS,true,rect.x,rect.y,rect.width,graphics.getFont().getHeight() + 1);
    }
    
    
    public int moveFocus (int amount, int status, int time) {
        this.invalidate(this.getSelectedIndex());
        return super.moveFocus(amount, status, time);
    }
    
    public void onFocus (int direction) {
        super.onFocus(direction);
    }
    
    protected void onUnFocus () {
        this.invalidate(this.getSelectedIndex());
    }
    
    public void refresh () {
        this.getManager().invalidate();
    }
    
    public void drawListRow (ListField listField, Graphics graphics, int index, int y, int width) {
        String[] rowString = (String[]) _listData.elementAt(index);
        graphics.setGlobalAlpha(255);
        graphics.setFont(Font.getDefault().getFontFamily().getFont(Font.PLAIN, 24)); //17
        
        
        int selectedIndex = getSelectedIndex();
        
        if (selectedIndex == index) {
            graphics.setColor(Color.BLUE);
        } else {
            graphics.setColor(Color.BLACK);
        }
        
        int clubOffset = 100;
            
        if (Graphics.getScreenHeight() > 240) {
            clubOffset = 150;
        }
        
        int x = 0;
        graphics.drawText(rowString[1], x, y, DrawStyle.HCENTER, width);
        //graphics.drawText(rowString, (0 - (clubOffset/2)), y, DrawStyle.HCENTER, width);
    }
    
    public Object get(ListField listField, int index) {
        String rowString = (String) _listData.elementAt(index);
        return rowString;
    }
    
    public int indexOfList (ListField listField, String prefix, int start) {
        for (Enumeration e = _listData.elements(); e.hasMoreElements(); ) {
            String rowString = (String) e.nextElement();
            
            if (rowString.startsWith(prefix)) {
                return _listData.indexOf(rowString);
            }
        }
        
        return 0;
    }
    
    public int getPreferredWidth(ListField listField) {
        return 3 * listField.getRowHeight();
    }
    
    protected boolean trackwheelClick (int status, int time) {
        invalidate(getSelectedIndex());
        return super.trackwheelClick(status, time);
    }
}
__________________
Praveen K
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Honeywell Access Controller Motherboard PRO42IC - NIB **  ** picture

Honeywell Access Controller Motherboard PRO42IC - NIB ** **

$850.00



Used & Tested ASUS DSAN-DX Motherboard picture

Used & Tested ASUS DSAN-DX Motherboard

$200.92



Used & Tested IEI IMBA-8650GR-R22-NOCB-BULK IMBA-8650GR Motherboard picture

Used & Tested IEI IMBA-8650GR-R22-NOCB-BULK IMBA-8650GR Motherboard

$380.88



Used & Tested IEI Rocky-4784EV V1.2 Industrial Motherboard picture

Used & Tested IEI Rocky-4784EV V1.2 Industrial Motherboard

$302.20



Used & Tested IBASE IB520-R Motherboard picture

Used & Tested IBASE IB520-R Motherboard

$492.30



Intel BQBG1260004C AA G10491-306 Desktop Mother Board picture

Intel BQBG1260004C AA G10491-306 Desktop Mother Board

$250.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.