11-24-2009 09:28 PM
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
Solved! Go to Solution.
11-24-2009 11:36 PM
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.
11-25-2009 12:24 AM
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.
11-25-2009 12:50 AM
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?
11-25-2009 01:05 AM
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.
11-25-2009 01:10 AM
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()..
11-25-2009 01:20 AM
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;
}
}
11-25-2009 02:12 AM
Thank you. I got it.
Thanks.
11-25-2009 02:27 AM
Thanks for updating us.