Загрузка изображения из URL в пользовательском адаптере для ListView (Android Studio)

В то время как растровое изображение кажется правильным, переменная userBitmap останется нулевой. Хотя при прокрутке вверх или вниз на моем планшете новые строки списка будут содержать изображения, но они все одинаковые и неправильные. Действительно, действительно запутался. Я пробовал несколько различных способов получения изображения из Интернета. Любая помощь очень ценится.

Мой кастомный адаптер:

public class MessagesArrayAdapter extends ArrayAdapter<ChatData>
{
    Bitmap userBitmap;

public MessageArrayAdapter(Context context, List<ChatData> objects)
{
    super(context, 0, objects);
}

public View getView(int position, View convertView, ViewGroup parent)
{
    ChatCell chatCell = new ChatCell();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    convertView = inflater.inflate(R.layout.cell_chat, parent, false);

    chatCell.usernameTextView = (TextView) convertView.findViewById(R.id.usernameTextView);
    chatCell.messageTextView = (TextView) convertView.findViewById(R.id.messageTextView);
    chatCell.userImageView = (ImageView) convertView.findViewById(R.id.userImageView);

    ChatData chatData = getItem(position);

    // Get user image from web
    new loadImageAsync().execute(chatData.avatarURL);

    chatCell.userImageView.setImageBitmap(userBitmap);
    chatCell.usernameTextView.setText(chatData.username);
    chatCell.messageTextView.setText(chatData.message);

    return convertView;
}



private static class ChatCell
{
    TextView usernameTextView;
    TextView messageTextView;
    ImageView userImageView;
}

private class loadImageAsync extends AsyncTask<String, Void, Double>{
    @Override
    protected Double doInBackground(String... params) {

        userBitmap = loadImage(params[0]);


        return null;
    }
}


public Bitmap loadImage(String str) {

    InputStream instream = null;
    try {
        HttpGet httpRequest = new HttpGet(URI.create(str));
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
        HttpEntity entity = response.getEntity();
        BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
        instream = bufHttpEntity.getContent();
        Bitmap myBitmap = BitmapFactory.decodeStream(instream);

        return myBitmap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    } finally {
        //close input
        if (instream != null) {
            try {
                instream.close();
            } catch (IOException ioex) {
                // Handle error
            }
        }
    }

}

}

Ответы на вопрос(1)

Ваш ответ на вопрос