I have a android app having a layout containing a Listview, which is inflated with
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.disc_row, parent, false);
the “R.layout.disc_row” is containing a SurfaceView drawing a canvas. so each row within the ListView is containing a Canvas. while scrolling the list the canvas is staying at its place while the other elements of the row are scrolling. I think its a poor behaviour of the device. the same app is not drawing anything on the emulator until clicking on a ListItem.
Is there any better strategy for drawing inside ListViews (no Bitmap, just some lines) maybe with Paint?
emulator sys it is doing too much work in the activity.
thanks in advance
attached CLASS
public class DrawDiscInListView extends SurfaceView implements
SurfaceHolder.Callback {
private static final String TAG = "DISCONT SurfaceView";
public DrawDiscInListView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
tryDrawing(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int frmt, int w, int h) {
tryDrawing(holder);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
private void tryDrawing(SurfaceHolder holder) {
Log.i(TAG, "Trying to draw...");
Canvas canvas = holder.lockCanvas();
if (canvas == null) {
Log.e(TAG, "Cannot draw onto the canvas as it's null");
} else {
drawMyStuff(canvas);
holder.unlockCanvasAndPost(canvas);
}
}
private void drawMyStuff(final Canvas canvas) {
Random random = new Random();
Log.i(TAG, "Drawing...");
canvas.drawRGB(255, 128, 128);
}
}
I did some research, I would like to share here:
Instead of using SurfaceView I used finally ImageView:
I used Canvas for creating a Bitmap and then used the bitmap in the Listview. It works fine and without loss of performance.