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;
}
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);
}
});
设置图像后尝试使 imageView 失效()。
Use notifyDataSetChanged(); After updating ur image in adapter.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.