public View getView(final int pos, View arg1, ViewGroup arg2) {

    ViewHolder holder;
    View view = arg1;

    if (arg1 == null) {
        holder = new ViewHolder();
        System.out.println("Inflating view");
        arg1 = mInflater.inflate(R.layout.inflatefreedownlod, arg2, false);
        holder.im = (ImageView) arg1.findViewById(R.id.imf1);
        holder.tv1 = (TextView) arg1.findViewById(R.id.tvf1);
        holder.tv2 = (TextView) arg1.findViewById(R.id.mini1);
        holder.tv3 = (TextView) arg1.findViewById(R.id.m1);
        arg1.setTag(holder);

    } else {

        holder = (ViewHolder) arg1.getTag();
    }

    holder.tv1.setText(NAME.get(pos).toString());
    holder.tv2.setText(contentName.get(pos).toString());
    holder.tv3.setText(minidescp.get(pos).toString());
    URL url1;

    try {

        url1 = new URL(imurl.get(pos).toString());
        bmp = BitmapFactory.decodeStream(url1.openConnection().getInputStream());
        holder.im.setImageBitmap(bmp);
        //bmp.recycle();

    } catch (Exception e) {
        e.printStackTrace();
    }

    arg1.setOnClickListener(new OnClickListener() {

                            @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            for (int i = 0; i < NAME.size(); i++)
                if (pos == i) {
                    getFreeContent(Cid.get(pos).toString(), Vid.get(pos).toString(), contentName.get(pos).toString());
                }

        }

    });

    return arg1;
}

我看到一只logcat,它显示了三次膨胀的视图。在模拟器上测试时,ListView中显示了3个线性布局。为什么我的观点每次都是空的?。视图每次都会膨胀。我的密码有问题吗

最佳答案

如果列表中有三个项目,并且屏幕上有足够的空间容纳ListView中的三行,则使用getView()null调用View三次以创建这三行。不能回收当前正在使用的行。

10-07 20:02