Domanda

Background: I'm filling gridview with imageviews using baseadapter. Imageview's resources are downloaded using AsyncTask. I get a callback from onPostExecute method as success or failure. And I use this callback in adapter's getView method.

Problem If url for imageview returns 404 error, gridview has some empty spaces because of 404 error. I can remove those items and call notifydatasetchanged, but this time it refreshes all gridview from the start. Although i keep errored items in somewhere, remove them and call notifydatasetchanged once for all, it seems gridview is filled twice in application.

Question I want to load images in gridview without any gaps. For instance if there are 9 images and forth and sixth images return 404 error, then i want to see only seven items in gridview

I hope my question is clear. Thanks for your help.

È stato utile?

Soluzione

I solved my problem like this. When i catch a callback from 404 error, in baseadapter getview method,

DownloadCallback dc = new DownloadCallback(){

       public void onSuccess(String downloadedString){

       }

       public void onFailure(int callbackID){
          System.out.println("onFailure - " + callbackID);

          if( callbackID < getCount()) // in case of out of index exception
             rows.remove(callbackID); 
          //parent.removeViewAt(callbackID); we cannot remove it is UNSUPPORTED
          reloadFromPosition(callbackID, imageView, parent);
        }
     };

and reloadFromPosition method is like that;

private void reloadFromPosition(int position, View convertView, ViewGroup parent)
{
    if( position < getCount())
    {
        System.out.println("reloadFrom - if - " + position);
        getView(position, convertView, parent);
        reloadFromPosition(position + 1, parent.getChildAt(position +1), parent);
    }

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top