0

is there anyway that I can cache the images on a FlipView? I can already load (20) images on the FlipView and Im doing it using AsyncTask because it takes a lot of time loading it. But my main question is, is there any way that when I select an item in the FlipView, say item #15, then the details page for #15 is shown, and when I press back, the FlipView will still show #15 and not reload the whole FlipView and start again on item #1. I am loading the images on my FlipView like this:

private int imageID[]={
         R.drawable.x1,
         R.drawable.x2,
         R.drawable.x3,
         R.drawable.x4,
         R.drawable.x5,
         R.drawable.x6,
         R.drawable.x7,
         R.drawable.x8,
         R.drawable.x9,
         R.drawable.x10,
         R.drawable.x11,
         R.drawable.x12,
         R.drawable.x13,
         R.drawable.x14,
         R.drawable.x15,
         R.drawable.x16,
         R.drawable.x17,
         R.drawable.x18,
         R.drawable.x19,
         R.drawable.x20
        };
ImageView[] image = new ImageView[20];
private ViewFlipper FlipV = null;

private class asyncImage extends AsyncTask<Void, Void, Void>{
    int i;
    @Override
    protected Void doInBackground(Void... params) {
        for (i=0;i<imageID.length;i++){
            image[i] = new ImageView(getBaseContext());
            image[i].setImageResource(imageID[i]);
            image[i].setBackgroundDrawable(getResources().getDrawable(R.drawable.border));
            image[i].setScaleType(ImageView.ScaleType.FIT_XY);
        }
        return null;
    }

    protected void onPostExecute(Void result){
        for (int x=0;x<imageID.length;x++){
        FlipV.addView(image[x]);
        }
        count = 1;
        progDialog.dismiss();
        txItem.setText(Integer.toString(count) + "/" + (imageID.length));
    }
}

private void nextImage(){
    if(count < imageID.length) {
        this.FlipV.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
        this.FlipV.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
        this.FlipV.showNext();
        count++;
        txItem.setText(Integer.toString(count) + "/" + (imageID.length));
    }

}
SleepNot
  • 2,982
  • 10
  • 43
  • 72

1 Answers1

1

You can try out the Image loading mechanism given in the Android Universal ImageLoader. This is somewhat the optimized solution of the Fedor's - Lazy list with images

So you can try out ImageLoader class and implement the logic in your app to resolve problem.

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295