how to capture listfield scroll to bottom in blackberry 7

后端 未结 1 1510
日久生厌
日久生厌 2021-01-26 06:44

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

相关标签:
1条回答
  • 2021-01-26 07:22

    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.

    0 讨论(0)
提交回复
热议问题