Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview多次调用的getView方法_Android_Listview_Android Listview_Getview - Fatal编程技术网

Android Listview多次调用的getView方法

Android Listview多次调用的getView方法,android,listview,android-listview,getview,Android,Listview,Android Listview,Getview,列表视图适配器中的getView方法在位置0处多次调用 因此,加载此活动需要更多的时间并且每次调用getView时都在Imageview中设置Bitamp 我还尝试将列表视图高度设置为fillparent,但没有解决我的问题 Xml文件中的ListView <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" &

列表视图适配器中的getView方法在位置0处多次调用
因此,加载此活动需要更多的时间
并且每次调用getView时都在Imageview中设置Bitamp

我还尝试将列表视图高度设置为fillparent,但没有解决我的问题

Xml文件中的ListView

      <RelativeLayout android:layout_width="match_parent"
                      android:layout_height="wrap_content" >
       <ListView  android:id="@+id/lv_order_list"
                        android:layout_width="match_parent"
                        android:layout_height="fill_parent"
                        android:divider="@android:color/transparent"
                        android:dividerHeight="0dp"
                        android:listSelector="@android:color/transparent" >
                    </ListView> 
   </RelativeLayout>

getView
在滚动期间将被多次调用,这就是
ListView
的工作方式

为了提高性能,您可以使用两种技术:
1) 查看回收-你做错了什么

public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.your_layout, null);
    }

    TextView text = (TextView) convertView.findViewById(R.id.text);
    text.setText("Position " + position);

    return convertView;
}
2) 使用ViewHolder图案

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.your_layout, null);

        holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.text);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.text.setText("Position " + position);

    return convertView;
}

private static class ViewHolder {
    public TextView text;
}
3) 异步加载图像 它的大写字母是P,您缺少
Context
参数

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); 

代码借用自

你没有说明你的问题。。众所周知,android多次调用位置0上的getView。我不确定这是一个bug还是一个特性,但这是一个系统问题。谁是listview的父对象?它是线性的、相对的、框架布局吗?相对布局是listview的父级
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);