在listview高度更改后多次调用Android getView()

时间:2013-09-20 18:20:44

标签: android android-listview

所以我有这个列表视图,高度为 fillparent ,主要是它占据屏幕大小的一半,但之后我需要更改此列表视图的父布局。在这里我开始注意到应用程序是疯狂的,经过一些诊断我明白来自适配器的 getView()被调用了很多次,

PS:当listview高度处于 wrapcontent 时,我将这个问题暂时解决,将其更改为 fillparent 解决了问题,但是再次出现了高度变化,< / p>

如果有人对此有任何线索,请不要错过, 谢谢所有

2 个答案:

答案 0 :(得分:0)

如果您认为您的应用因getView()方法而滞后,则应尝试对其进行优化。 Android系统保留了一个可以重用的对象池,这些对象是作为convertView参数提供的。

@Override

    public View getView(int position, View convertView, ViewGroup parent) {
             if (convertView == null) {
              LayoutInflater inflater = context.getLayoutInflater();
              convertView = inflater.inflate(R.layout.rowlayout, null);
             }

             // asign correct values to your items - example:

             TextView text = (TextView) convertView.findViewById(R.id.text);
             text.setText(values.get(position));

             //

            return convertView;
    }

答案 1 :(得分:0)

谢谢大家,我弄错了, 当我试图改变其父母的身高时,我错了 RelativeLayout.LayoutParams(ViewGroup.LayoutParams。 WRAP_CONTENT ,ViewGroup.LayoutParams。 WRAP_CONTENT );

将其更改为FILL_PARENT后,问题就消失了 再次感谢您的时间

相关问题