Skip to main content

BlackBerry ListField Tutorial Part 1

the same with the toolbar tutorial. im going to split these tutorial into parts. These Part 1 will be consist of any stuff that pretty much simple.

Requirements :

- Blackberry OS 5
- Java Eclipse Plugin for Blackberry

today i want to create a simple tutorial from simple ListField to a complex and custom ListField.
maybe not tutorial but a review from the resources over the internet.

if you want to know the differences from objectListField here some article or maybe an answer for you :
http://stackoverflow.com/questions/3573941/how-to-customize-objectlistfield

Syntax Highlight by http://tohtml.com/java/

lets starts with the one that blackberry have on How to - Make list items appear on a screen.

with their code here is what you'll get.

it is an empty string but the list field is there. i think you can scroll it down



Blackberry ListField with Text
now its something that i got from books.

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.MainScreen;

public class test2Screen extends MainScreen implements ListFieldCallback {
    protected String listMembers[] = {"itema1","itemb2","itemc3","itemd4"};
    /*
     * From The Book Blackberry Java Application Development
     */
    public test2Screen() {
        super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
        // TODO Auto-generated constructor stub
        ListField mylist = new ListField();
        mylist.setCallback(this);
        mylist.setSize(4);
        
        add(mylist);
        
    }

    public void drawListRow(ListField listField, Graphics graphics, int index,
            int y, int width) {
        // TODO Auto-generated method stub
        //graphics.drawText("test"+Integer.toString(index),0,y,0,50);
        
        graphics.setColor(Color.BLUE);
        graphics.setBackgroundColor(Color.YELLOW);
        graphics.setFont(Font.getDefault().derive(Font.BOLD));
        graphics.drawText(this.listMembers[index], 0, y,50);
        
    }

    public Object get(ListField listField, int index) {
        // TODO Auto-generated method stub
        return listMembers[index];
    }

    public int getPreferredWidth(ListField listField) {
        // TODO Auto-generated method stub
        return 200;
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        // TODO Auto-generated method stub
        return -1;
    }

} 


with that code you'll get this list field with text :

it doesn't have click able field. and its still just one field per row.

next time i'll try to make more interesting.  Please read the Part 2 of the tutorial its Listfield that support Image.

Go to Part 2

Comments

Popular posts from this blog

JavaScript Real Time Calculation

I've been around looking for javascript that can do Real Time Calculation. javascript real time calculation, javascript real time calculation textbox. by some lucky keywords i found this code. this is exactly the code that i want. it really do the real time calculation. and it doesn't need onChange or OnBlur function. Just try it Example + = this is the javascript code <script type='text/javascript' > function startCalc(){   interval = setInterval("calc()",1); } function calc(){   one = document.autoSumForm.firstBox.value;   two = document.autoSumForm.secondBox.value;   document.autoSumForm.thirdBox.value = (one * 1) + (two * 1); } function stopCalc(){   clearInterval(interval); } </script> this is the html code <form name="autoSumForm">   <input class="right" type=text name="firstBox" value="" onFocus="startCalc();" onBlur="stopCalc();"><br...

BlackBerry ListField Tutorial Part 2

Blackberry ListField with Clicked Row this time i create based on rtm4bb code. it used manager as TableRowManager to create the field for each row. first i create MenuListField.java

MySQL and Java Developer's Guide

Now we begin the second book and thats called MySQL and Java Developer's Guide. Book before this is quiet advance for beginner but still for beginner. And i notice that previous book had only 4 chapter. Ill read that book again. Okay Lets start. This book consist MySQL and Java plus Connector/J that connect Java to MySQL. This book is perfect for beginner but not beginner in programming. I think that this book is a hardcore book. Everything they wrote even if they use GUI Object like form and button they only use a "Notepad" or should i say "Text Editor". i really love this book. From this book you need to install three things to make the code in the book work. a. Install mySql b. Install Java SDK @ http://java.sun.com/j2se/1.4.1/download.html. c. Installing Connector/J @mysql.com version 3.0 thats from the book. I use this : jdk-1_5_0_11-nb-5_5-win-ml.exe notice the nb-5_5 that means itll install netbeans 5.5. netbean 5.5 is IDE for jdk 1.5. its devel...