android - 列表绑定(bind)后在自定义 ListView 中设置 ImageView 的源

标签 android listview android-listview imageview

我有一个绑定(bind)了自定义适配器的 ListView,它工作正常:

private class Placeslist extends ArrayAdapter<ArrayList<String>> {

    private ArrayList<ArrayList<String>> items;

    public Placeslist(Context context, int textViewResourceId,
            ArrayList<ArrayList<String>> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.locationgpsrow, null);
        }
        ArrayList<String> o = items.get(position);
        if (o != null) {
                        // Binding here
                        TextView tv1 = (TextView) v.findViewById(R.id.txt1);
                        tv1.setText(o.get(0));
                        ImageView imView = (ImageView) v.findViewById(R.id.imageView1);
                        //o.get(1) // Image url e.g. http://www.some-website/image.jpg
                     }
        return v;
    }
}

我的一个数组元素中有一个图像源 url,我需要下载图像并将其设置为 ListView 项自定义布局中的 ImageView。而且,我也有代码!!

ImageView imView = (ImageView) findViewById(R.id.imageView1);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            is = conn.getInputStream();
            bmImg = BitmapFactory.decodeStream(is);
            is.close();

imView.setImageBitmap(Bitmap.createScaledBitmap(bmImg, 宽度, 高度,真实));

我可以在上面的 getView() 中使用它来设置 imageView 源。但我想要的是让 ListView 绑定(bind)到适配器而不加载图像(因为这将是繁重的过程)。然后在加载 listView 之后,开始分别绑定(bind)行中的所有 ImageView。他们是实现此目的的方法还是可以将图像下载过程与 listView 绑定(bind)分开的任何方法?

最佳答案

你必须使用下面的库来在运行时加载图像:-

Universal loader lib

Picasso

Urlhelper

关于android - 列表绑定(bind)后在自定义 ListView 中设置 ImageView 的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23753834/

相关文章:

java - 为什么我不能在 ormlite 中使用自定义 DAO 类?

android - 如何通过单击其中的按钮来获取列表项位置?

android - 我总是收到 1 台设备的不同注册 ID

android - 使用 "MultiAutoCompleteTextView"时如何用空格替换逗号

android - SQLite rawQuery 不返回任何带有整数参数的结果

Android - 列表项不会立即刷新

android - listview 中的复选框在 android 的暂停时被重置

android - 单击 Item 时 ListView 打开 Activity ?

android - 将数据添加到 fragment 的 ListView

android - 获取另一个 Activity 的值(value)放在另一个 Activity 的 ListView 的编辑文本中