D
D
dllweb2014-08-01 07:34:06
Android
dllweb, 2014-08-01 07:34:06

Late rearrangement of images in ListView via ImageLoader, How to fix?

There is a list based on ImageLoader, its config in custom adapter looks like

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getContext())
             .memoryCacheExtraOptions(480, 800) // width, height
             .threadPoolSize(5)
             .threadPriority(Thread.MIN_PRIORITY + 2)
             .denyCacheImageMultipleSizesInMemory()
             .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // 2 Mb 
             .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
             .build();
             
             imageLoader.init(config);
             
             
             imageLoader.displayImage(models.getImg(), holder.imageView);

And this is how the adapter is filled in the main Activity
@Override
    protected void onCreate(Bundle savedInstanceState) {
    
    
    StrictMode.enableDefaults();
    
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        TextView tv = (TextView) findViewById(R.id.answer);
        ListView lv = (ListView) findViewById(R.id.list);
        
        data = request.doInBackground();
        
        try {
      
        	JSONArray json = new JSONArray(data);
  
      for(int i=0; i < json.length(); i++){
        
        
         modelrow = new Models(	 
             json.getJSONObject(i).getString("id").toString(),
             json.getJSONObject(i).getString("model").toString(), 
             "http://example.com"+json.getJSONObject(i).getString("preview").toString()
             			  );
        
         fetch.add(modelrow);
  
      }
      
      adapter = new ModelAdapter(MainActivity.this, R.id.list, fetch);
      lv.setAdapter(adapter);
      
      
    } catch (JSONException e) {

      e.printStackTrace();
    }

Friends, let me explain again, the problem is that when you open this application, the view list is loaded.
wokcBBQzzMo.jpg
When you scroll through this list, the images begin to mismatch the models, only after 1-2 seconds the necessary ones are loaded. How can this be fixed, here is the working status log from LogCat
08-01 00:20:54.287: D/dalvikvm(1291): GC_FOR_ALLOC freed 316K, 15% free 4004K/4708K, paused 22ms, total 24ms
08-01 00:20:54.687: W/ImageLoader(1291): Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
08-01 00:20:54.697: W/ImageLoader(1291): Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
08-01 00:20:54.717: W/ImageLoader(1291): Try to initialize ImageLoader which had already been initialized before. To re-init ImageLoader with new configuration call ImageLoader.destroy() at first.
08-01 00:20:55.287: D/dalvikvm(1291): GC_FOR_ALLOC freed 298K, 16% free 3996K/4708K, paused 24ms, total 24ms
08-01 00:20:55.587: D/dalvikvm(1291): GC_FOR_ALLOC freed 307K, 19% free 3854K/4708K, paused 24ms, total 25ms
08-01 00:20:55.597: I/Choreographer(1291): Skipped 62 frames!  The application may be doing too much work on its main thread.
08-01 00:20:55.817: I/Choreographer(1291): Skipped 46 frames!  The application may be doing too much work on its main thread.

How can this be corrected?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander, 2014-08-01
@pod_proteinom

I have the same problem... The only solution I've found so far (not the best for me) is resetting the view before loading (.resetViewBeforeLoading(true)) and adding a stub image (.showImageOnLoading())

A
anyd3v, 2014-08-01
@anyd3v

What about: in-memory cache, resource usage shown during download?
(as far as I know, it is disabled on the memory cache account and .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) will not enable it, you need to set .cacheInMemory(true).cacheOnDisk(true)) in the
options since it takes some time to work with bitmaps.
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder must be moved to Application#onCreate (because these are global settings)

C
Copperfield, 2014-08-01
@Copperfield

Try adding .resetViewBeforeLoading(true) to the options builder.

M
Marat S, 2014-08-01
@aratj

show me the adapter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question