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
flybirdtt
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified
Accepted Solution

How to udpate listfield specially rows

This app i developed is a story reader. It has a screen  which contained a listfield. I hope after i can update the listfield.

May be just change one row of this listfield with specially index.

But i don't know how to implement it.

Now i just use the method like this:

for(int i=0;i<listfield.getSize();i++)

{

listfield.delete(0);

listfieldcallback.remove(0);

}

for(int i=0;i=Vecotr.size();i++)

{

listfield.insert(i);

listfieldcallback.insert(object,i);

}

then call this listfield manager: listfieldmanager.invalidate();

I think there should be have better way to update the specially rows of listfield

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to udpate listfield specially rows

If you know the which List Row has to be removed or updated, Using the Index you can do it that time no need of using the for loop.


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
flybirdtt
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: How to udpate listfield specially rows

Yes, I know the index. But how to update this listRow, I mean how to set the new value for this row.

And call listfield.invalidate(int index) to call the drawlist method from listfield callback.

Can you show me a example.


Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to udpate listfield specially rows

You know which index you have to update, remove that row from list and insert the new content to the same location. Is it not invalidating the change on Screen?


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
flybirdtt
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: How to udpate listfield specially rows

I have tested like this.

 i use listfield.delete(0), and after that , i use listfield.insert(0). but this new listrow can not replace the old one .

For example: the size of a listfield is 10, and i delete(0), and insert(0). but even i use insert(0). The index of new row is not 0,the actual index is 10.

Sorry for my poor english.

Thanks very much for your reply.

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to udpate listfield specially rows

In your ListFieldCall back when you insert the new element it might just added to the Vector, Just give a look at the methods you are using.  You may have to use Vector.insertElementAt()..


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.
Developer
zany
Posts: 222
Registered: ‎11-11-2009
My Device: Storm

Re: How to udpate listfield specially rows

I think this sample will solve your problem

 

 

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;

public class MySample extends UiApplication
{
    private MyScreen _fistScreen;

    public static void main(String[] args)
    {
        MySample instance = new MySample();
        instance.enterEventDispatcher();
    }

    public MySample()
    {
        _fistScreen = new MyScreen();
        invokeAndWait (new Runnable()
        {
            public void run()
            {
                pushScreen (_fistScreen);
            }
        });
    }
}

class MyScreen extends MainScreen
{
    public MyScreen ()

   {
        super();

        ListBox lstBox;

        setTitle ("My Screen");
        lstBox = new ListBox (20, "My Screen");
        lstBox.setEmptyString ("Test Empty String", DrawStyle.LEFT);
        lstBox.setCallback (lstBox);
        add (lstBox);
    }
}

class ListBox extends ListField implements ListFieldCallback
{
    private String _msg;
    private int _selectedRow;

    public ListBox (int noOfRows, String msg)
    {
        super (noOfRows);
        _selectedRow = -1;
        _msg = msg;
    }

    public int getPreferredWidth()
    {
        return 360;
    }

    public int getPreferredHeight()
    {
        return 480;
    }
   
    public void drawListRow (ListField lstField, Graphics g, int index, int y, int width)
    {
        String msg;

        msg = _msg;
        if ((_selectedRow != -1) && (index == _selectedRow))
            msg += " got selected";
        g.drawText (msg + " " + index, 0, y, 0, width);
    }

    public Object get (ListField lstField, int index)
    {
        return null;
    }

    public int getPreferredWidth (ListField lstField)
    {
        return 360;
    }

    public int indexOfList(ListField lstField, String prefix, int start)
    {
        return lstField.indexOfList (prefix, start);
    }

    protected boolean touchEvent (TouchEvent message)
    {
        switch (message.getEvent() )
        {
            case TouchEvent.CLICK:
                super.touchEvent (message);
                _selectedRow = getSelectedIndex();
                invalidate();
        }

        return false;
    }
}

with regards,
Vignesh J

-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Don't forget to mark your post as solved if you get the answer and dont forget to give kudos if the answer is useful for you.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Please use plain text.
Developer
flybirdtt
Posts: 153
Registered: ‎09-03-2009
My Device: Not Specified

Re: How to udpate listfield specially rows

Thank you. I got it.

Thanks.

Please use plain text.
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to udpate listfield specially rows

Thanks for updating us.


Use Search. "Accept Solution" If the problem is resolved.
Please use plain text.