Search code examples
androidandroid-image

Download many images, then set and unset them as user scrolls to and away


My goal: Download many images and allow the user to scroll though them seemingly endlessly.

My issue: I am having trouble efficiently setting and unsetting images to conserve ram as the user scrolls. I am new to android so I am sure there is a much better way then I am doing.

My current method: this is just an outline

//I have a listener setup for the scroll 
 onScrollChanged(ScrollViewExt scrollView, int x, int y, int oldx, int oldy){
//if the user has scrolled 1000 pix and there is currently no other updating thread running
      if(((y%1000==0)||(y%1000>990))&&!updating){
             updating=true;
             AsyncTask<String, Void, Void> update = new   UpdateViews().execute(y+"");
    }
 }
//updateviews essentially iterates though all my views and calls a method in each one that returns getLocationOnScreen().  
// This in turn is used to determine if the view is far away enough from the scroll to have its image removed or has come back to the area and is added to an appropriate array-list as to be altered later on the UI thread
//everything is saved to a array-list and the views are updated on the onPostExecute() because they have to be done on the main thread

Now I know there are some issues with what i wrote as it is just preliminary code but is causes the ui to lag and occasionally crash. I am looking for ideas on how to do this efficiently.


Solution

  • Used a listview with a ton of customization