まあ、それは可能です。
ArrayAdapter のメソッド getView および add をオーバーライドします。
たとえば、テストケースとして何をしたか:
public class custom_row extends ArrayAdapter<String> {
String newItem = "";
Boolean doRefresh = true;
public custom_row(Context context, int resource, ArrayList<String> objects) {
super(context, resource, objects);
}
public custom_row(Context context, int resource, String[] objects) {
super(context, resource, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
String itemValue = getItem(position);
if (doRefresh == false && itemValue != newItem) {
return convertView;
}
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = inflater.inflate(R.layout.customr_row, parent, false);
ImageView myImageView = (ImageView) customView.findViewById(R.id.imageView);
String url = "https://urltoimage/image.jpg";
(new DownloadImageTask(myImageView)).execute(url);
TextView myTextView = (TextView) customView.findViewById(R.id.myCustomText);
myTextView.setText(itemValue);
return customView;
}
public void addNewItemToList(String item) {
this.newItem = item;
this.doRefresh = false;
add(item);
}
private class DownloadImageTask extends AsyncTask<String, Integer, Bitmap>{
private ImageView mImageView;
public DownloadImageTask(ImageView imageView) {
this.mImageView = imageView;
}
@Override
protected Bitmap doInBackground(String... params) {
URL url = null;
Bitmap bmp = null;
try {
url = new URL(params[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
InputStream stream = url.openStream();
bmp = BitmapFactory.decodeStream(stream);
} catch (IOException e) {
e.printStackTrace();
}
return bmp;
}
@Override
protected void onPostExecute(Bitmap bmp) {
this.mImageView.setImageBitmap(bmp);
}
}
}
初めてすべてのアイテムをロードすると、非同期スレッドによって画像が動的にロードされます。メソッド getView のコードの次の部分は、リストが完全に更新されないようにするため、画像の点滅を防ぎます。
String itemValue = getItem(position);
if (doRefresh == false && itemValue != newItem) {
return convertView;
}
新しい項目がリストに追加されると、ArrayAdapter はリストを再度調べます。現在の位置にあるアイテムが新しく追加されたアイテムかどうかを確認するだけです。そうでない場合は、古いビューである convertView を返すか、アイテムをロードしてカスタム ビューを返します。