0

I want to update the source of image view after some time but by changing the source it will overlap with the previous one. this is the complete code of my activity class. I tried by both runnable and countdowmtimer but the problem is still

enter image description here[1]

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_content_pop_up);
        imageUrl=new ArrayList<>();
        for(int i=1;i<=3;i++)
        {
            imageUrl.add("https://www.gstatic.com/webp/gallery3/"+i+".png");
        }
        LinearLayoutManager layoutManager=new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
        recyclerImagevIew=(RecyclerView)findViewById(R.id.image_recycler_view);
        recyclerImagevIew.setLayoutManager(layoutManager);
        ImagePopupAdapter imagePopupAdapter =new ImagePopupAdapter(this,imageUrl);
        recyclerImagevIew.setAdapter(imagePopupAdapter);
        background_Image=(ImageView) findViewById(R.id.background_image);
        cross_sign =(TextView)findViewById(R.id.cross_button);
        cross_sign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //  StartAsyncTask();
        // StartTimer();
        handler=new Handler();
        runnable= new Runnable() {
            @Override
            public void run() {
                if(index<imageUrl.size()) {
                    Glide.with(getApplicationContext()).load(imageUrl.get(index)).into(background_Image);
                    index++;
                    handler.postDelayed(runnable, 5000);
                }
            }
        };
        handler.postDelayed(runnable,1000);
    }
    public void StartTimer()
    {
        CountDownTimer timer = new CountDownTimer(15000, 5000) //10 second Timer
        {
            public void onTick(long l)
            {
                Glide.with(getApplicationContext()).load(imageUrl.get(index)).into(background_Image);
                index++;
            }

            @Override
            public void onFinish()
            {
                SystemClock.sleep(5000);
                handler.post(new Runnable() {
                    public void run() {
                        finish();
                    }
                });
            };
        }.start();

    }
Duck Dodgers
  • 3,409
  • 8
  • 29
  • 43

1 Answers1

1

How can i change the image source of ImageView after some time progmatically

This issue occur becaouse of Glide will cashing all image urls so you have to use diskCacheStrategy(DiskCacheStrategy.NONE) to resolve the issue. I am sure that you not get this issue during app runs very first time.

Note: Please check app in real device.

Glide.with(DemoActivity.this)
    .load(Uri.parse("file://" + imagePath))
    .diskCacheStrategy(DiskCacheStrategy.NONE)
    .skipMemoryCache(true)
    .into(mImage);

In your case

Glide.with(this)
            .load("")
            .apply(new RequestOptions()
                    .placeholder(R.drawable.ic_launcher_background)
                    .diskCacheStrategy(DiskCacheStrategy.NONE)
                    .skipMemoryCache(true))
            .into(view);

For more: Link

For more about the glide

ND1010_
  • 3,743
  • 24
  • 41