As mentioned above. First use the ViewHolder pattern, also use picasso to make image caching easy, if you need to use ImageSpannables you can use picasso like below.
ViewHolder {
ImageView icon;
TextView name;
TextView time;
TextView comment;
}
In your Adapter getView() do this
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = new View(); // use a layout inflator to inflate view
}
ViewHolder holder = (ViewHolder) convertView.getTag();
if (holder == null) {
holder.name = convertView.findViewById(R.id.nameView);
... // other views
}
holder.name.setText("new name");
new SetImageOnTextViewAsyncTask(context, holder.comment).execute("http://...");
}
Create a AsyncTask which takes the view you want to set the Image on and utilise Picasso
public SetImageOnTextViewAsyncTask extends AsyncTask<String, Void, Bitmap bmp> {
private final TextView textview;
private final Context context;
public SetImageOnTextViewAsyncTask(Context context, TextView textview) {
this.textView = textview;
this.context = context;
}
@Override
protected String doInBackground(String... urls) {
return Picasso.with(context).load(urls[0]).get(); // Picasso will cache you image and only download it once
}
@Override
protected void onPostExecute(ImageView result) {
textView.setText( new ImageSpan( result ), BufferType.SPANNABLE);
}
}
Finally instead of creating a new adapter all the time, just update the data structure of it and call notifyDataSetChanged. Have a method called updateData or something like that where you append items or change them, depending of what you need to do.