Custom List With Images in Blackberry

此生再无相见时 提交于 2019-12-06 16:02:55

Having looked at this only briefly, the problem appears to be that you are, in places, ignoring the 'y' position that is passed in to your drawListRow() method:

        public void drawListRow(ListField list, Graphics graphics,
                int index, int y, int w) {

Effectively the 'canvas' that you should be using to paint the current row (the row identified using int index) is bounded by the rectangle (0, y, w, list.getRowHeight()).

In fact, you can actually paint anywhere in the extent that belongs to the ListField, i.e. the area you can paint onto is actually the rectangle (0, 0, list.getWidth(), list.getHeight()). You can do this, but you shouldn't. If you go outside your row's rectangle you will be painting over another row.

In your case, painting outside the selected row is exactly what your code does. You do this:

                graphics.drawText("Hello", 10,
                        Display.getHeight() - 150);

This will actually be positioned on the ListField, 10 pixels in from the left and Display.getHeight() - 150 down from the top. It will be positioned at this point in the ListField, regardless of which row you are painting. So every row will put the Hello text in the same place.

So when coding your drawListRow(), make sure you offset all the positions to stay within the bounds of the row you are supposed to be painting. The origin of the area you are painting is (0, y), so offset all vertical positions using y. Do not use Display.getHeight(), use list.getRowHeight() to get the height you can paint (starting at y), and do not use Display.getWidth(), use the w variable that is passed in to get the width that you can paint. All your graphics actions should occur within these bounds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!