I have a listfield with many data, at first i load 10 records from server, i want to capture the event when the scroll has moved to bottom, that i can load more records from ser
If you are using ListField
, and you are performing custom painting by extending ListFieldCallback
, then you can detect that a row is focused inside the drawListRow
method:
public void drawListRow(ListField lf, Graphics g, int index, int y, int x) {
if (lf.isFocus() && lf.getSelectedIndex() == index) {
//The selected row is bein repainted
if(index == (lf.getSize() - 1)){
//The last row is being focused
}
}
}
Then you can request new elements in a worker thread. Block the GUI with a loading message.
This is a basic solution to the problem. In a real pro app, you'd preemtively request a new batch of elements when the user is about to reach the end of the list (selected row = size of the list - number of rows that fit in the screen). This way it can scroll down without waiting. You'd have to handle failed requests as well as multiple user initiated requests over the same batch.