0

I have some throuble with getting my GridView working as it should.

When I scrol some of the images are sliding much faster than other images (they will not stay in their row). Sometimes I am also able to scrol above the first line! If I skip to use the convertview I have not seen the problem.

---Some additional background--- The imageBufferLoader object below extends a component I am trying to develop. It works as a cash for objects (this time images) with two parameterised windows. One window for maximum objects cashed (to avoid memory problems) and a window for minimum objects loaded (in order to be prepared for scrolling). I have callables that are sent to an executor, one callable for filling the array and one for cleaning the array.

Maybe my problem is thread related.

Here is my adater:

public class WebImageSearchResultAdapter extends BaseAdapter implements
    PropertyChangeListener {
private ImageBufferLoader imageBufferLoader;
private Image image = new Image();
private Context context;
private Bitmap bitmapIC_Delete;
private static Handler handleUIEvents;
private LoggerAndroid logger;
private int lastPosRequest;
private RelativeLayout zeroView;

public WebImageSearchResultAdapter(Context context, Parameters parameters) {
    this.context = context;

    handleUIEvents = new Handler(Looper.getMainLooper()) {

        @Override
        public void handleMessage(Message msg) {

            notifyDataSetChanged();
            logger.LogD("Notify Data set Changed");

            super.handleMessage(msg);
        }

    };

    bitmapIC_Delete = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.ic_delete);
    logger = new LoggerAndroid(
            LoggerAndroid.isLoggingactivewebimagesearchresultadapter(),
            "WebImageSearchResultAdapter", "");

    Logger loggerImageBuffer = new LoggerAndroid(
            LoggerAndroid.isLoggingactiveimagebufferloader(),
            "ImageBuffer", "ImageBuffer");
    Logger loggerImageDataBuffer = new LoggerAndroid(
            LoggerAndroid.isLoggingactiveimagebufferloader(),
            "ImageDataBuffer", "ImageDataBuffer");

    imageBufferLoader = new ImageBufferLoader(loggerImageBuffer,
            loggerImageDataBuffer, parameters, false, 50, 50, false, true, 50, 200);
    imageBufferLoader.addChangeListener(this);
    try {
        imageBufferLoader.startService();
    } catch (TimeoutException e) {
        ExceptionHandler.getInstance(true).handleException(e);
    }
}

public void setParameters(Parameters parameters) {
    imageBufferLoader.setParameters(parameters);
    zeroView = null;
}

public int getCount() {
    // TODO Auto-generated method stub
    return 1000;
}

public Object getItem(int position) {

    return null;
}

public long getItemId(int position) {

    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    logger.LogD("ASK: " + position);
    lastPosRequest = position;
    RelativeLayout view2 = null;
    ImageView imageView = null;

    if (convertView == null) {

        view2 = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.listimageitem, parent, false);
    } else {

        view2 = (RelativeLayout) convertView;
    }

    imageView = (ImageView) view2.findViewById(R.id.imageThumbnail);


    if (position == 0 && zeroView != null) {
        view2 = zeroView;
    } else if (imageBufferLoader.isServiceRunning()
            && imageBufferLoader.isFillCleanRunning()) {
        try {

            if (imageBufferLoader.isDataAvailable(position)) {
                image = imageBufferLoader.getData(position);
                imageView.setImageBitmap(image.getThumbnailBitmap());
                if(position == 0){
                    zeroView = view2;
                }
                logger.LogD("RET IMAGE for: " + position);
            } else {
                imageView.setImageBitmap(bitmapIC_Delete);
                imageBufferLoader.loadData(position);
                logger.LogD("RET: IC_DELETE for position " + position +"Request added to Queue");
            }



        } catch (Exception e) {
            ExceptionHandler.getInstance(true).handleException(e);
            imageBufferLoader.stopService();
            imageView.setImageBitmap(bitmapIC_Delete);
            logger.LogD("RET: IC_DELETE for position " + position +" EXCEPTION");
        }
    } else {
        imageView.setImageBitmap(bitmapIC_Delete);
        logger.LogD("RET: IC_DELETE for position " + position +" SERVICE NOT RUNNING TRY TO RESTART");
        imageBufferLoader.start();
    }

    return view2;
}

public void propertyChange(PropertyChangeEvent event) {
    String proptertyName = event.getPropertyName();
    if (proptertyName.equals("Filling Ready")) {
        handleUIEvents.sendMessage(new Message());
    }

    if (proptertyName.equals("BufferCleared")) {
        if (imageBufferLoader.isServiceRunning()
                && imageBufferLoader.isFillCleanRunning()) {
            imageBufferLoader.loadData(lastPosRequest);
        }

    }
}

}

Here is my fragment with gridwiev

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<View
    android:layout_width="0dp"
    android:layout_height="fill_parent" />

<GridView
    android:id="@+id/gridview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnWidth="300dp"
    android:gravity="center"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:stretchMode="columnWidth"
    android:verticalSpacing="10dp" >
</GridView>

<View
    android:layout_width="0dp"
    android:layout_height="fill_parent" />

</LinearLayout>

Here is the layout I inflate in the adapter

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="300dp" >

<ImageView
    android:id="@+id/imageThumbnail"
    android:layout_width="300dp"
    android:layout_height="300dp"
/>

</RelativeLayout>
Eric1101000101
  • 531
  • 3
  • 6
  • 15
  • remove handle and property change listner try to implement using without it – Harsh Dev Chandel May 16 '13 at 11:56
  • Thanks for input. I have added some additional info above. I have some ideas about how I could modify the adapter but it would be interesting to get a better understanding for why I get the the problem described. – Eric1101000101 May 18 '13 at 07:40

0 Answers0