本文介绍了查看越来越膨胀每次在getView。 findViewById(...)做了很多次。我已经使用视图持有人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
}

我看这显示了充气查看3次logcat的。我有3个的LinearLayout显示在列表视图,当我进行测试的模拟器。为什么我认为空每次?查看也在每一次膨胀。什么毛病我的code

I see the logcat which shows Inflating View 3 times. I have 3 LinearLayout displayed in listview when i test it on emulator. Why is my view null everytime?. View also is inflated every time. Anything wrong with my code

推荐答案

如果您有三个项目在列表中,并且有空间在屏幕上三行的的ListView getView()将被调用三次以 查看来创建这些三行。你不能再利用的行为presently使用。

If you have three items in your list, and there is space on the screen for three rows in your ListView, getView() will be called three times with a null View to create those three rows. You cannot recycle a row that is presently in use.

这篇关于查看越来越膨胀每次在getView。 findViewById(...)做了很多次。我已经使用视图持有人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:09