BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-12-2010, 03:37 AM   #1 (permalink)
New Member
 
Join Date: Jun 2010
Model: 7100T
PIN: N/A
Carrier: Qwest
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
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


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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