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
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Problem in preparing list field

Hi 

i am facing problem in preparing list .there is a problem of i need to make custum list field.

 

 */
public final class MyScreen extends MainScreen
{
    /**
     * Creates a new MyScreen object
     */
    protected Vector listMembers ;;

    public MyScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("MyTitle");
        listMembers= new Vector();
        listMembers.addElement("ana");
        listMembers.addElement("sa");
        ListField l=new ListField();
        CustomList c=new CustomList(listMembers);
        //c.setCallback( listMembers);
add(c); } }

 

 

package mypackage;

import java.util.Vector;

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.Dialog;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;

public class CustomList extends ListField implements ListFieldCallback{
Vector _v;


public CustomList(Vector listMembers) {
// TODO Auto-generated constructor stub
_v= listMembers;
System.out.println("v"+_v.elementAt(0));
}

public void drawListRow(ListField listField, Graphics graphics, int index,
int y, int width) {
graphics.setColor(Color.BLUE);
graphics.setBackgroundColor(Color.YELLOW);
graphics.setFont(Font.getDefault().derive(Font.BOLD));
graphics.drawText((String) _v.elementAt(index), 0, y,50);
}

public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return _v.elementAt(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;
}

}

 

Please help me to solve this issue

Please use plain text.
Developer
simon_hain
Posts: 16,190
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Problem in preparing list field

i would suggest that you take a look at the list field samples that are available (for example by searching in the search box)
----------------------------------------------------------
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
Please use plain text.
Developer
ravi1989
Posts: 777
Registered: ‎07-21-2012
My Device: 9810

Re: Problem in preparing list field

Thanks for applying..i got the solution./

 

Thanks

Please use plain text.
Developer
peter_strange
Posts: 19,607
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem in preparing list field

Great, can you mark this as solved then - see Help link near the top for instructions if needed. 

Please use plain text.