0

I have a ImageView which will be updated every "x" seconds, obtained from a server.

The first updating the image changes correctly.

But in the next image has not updated anymore.

Does the first image is stored in memory, I would like to remove?

code:

 public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
        if(convertView ==null)
        {
            convertView = mInflater.inflate(R.layout.onlinelist,parent,false);
            holder = new ViewHolder();
            holder.tv = (TextView) convertView.findViewById(R.id.textView1);
            holderProfile = (ImageView) convertView.findViewById(R.id.usernameProfile);
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv.setText(usersInRange.get(position));
    String[] split = usersInRange.get(position).split(" ");
    final String firstSubString = split[0];
    AsyncHttpClient client = new AsyncHttpClient();
    client.get("xxxxxxxxx.com/uploads/" + firstSubString + ".jpeg", null, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                    final Bitmap image = BitmapFactory.decodeByteArray(responseBody, 0, responseBody.length);
                    holderProfile.setImageBitmap(image);
                    holderProfile.invalidate();


            }
            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            }

    });

    return convertView;
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38

4 Answers4

0

You are doing the Update on a Thread with Background Priority....

You will have to do run it on main Thread

Change this line:

holderProfile.setImageBitmap(image);

To this:

runOnUiThread(new Runnable() {
      @Override public void run() {
            holderProfile.setImageBitmap(image);
      }
});
Dennis Weidmann
  • 1,942
  • 1
  • 14
  • 16
0

try invalidate() of imageView after setting image.

Ashok Kumar
  • 1,226
  • 1
  • 10
  • 14
0

Use notifyDataSetChanged(); After updating ur image in adapter.

Ahmad Arslan
  • 4,498
  • 8
  • 38
  • 59
0

Remove holderProfile.invalidate(); from client.get(...) and put before the

AsyncHttpClient client = new AsyncHttpClient();

or you can try this one ImageView not refreshing/reflecting changes

Community
  • 1
  • 1
Nishant Dixit
  • 5,388
  • 5
  • 17
  • 29