Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.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
Java 为什么我的ListView呈现重复的项目?_Java_Android_Arrays_Listview - Fatal编程技术网

Java 为什么我的ListView呈现重复的项目?

Java 为什么我的ListView呈现重复的项目?,java,android,arrays,listview,Java,Android,Arrays,Listview,这就是我填充我的列表视图的方式: 这是一个场景: 1-创建两个阵列 2-创建RowItem类 3-创建ListAdapter 公共类ListAdapter扩展了BaseAdapter{ 语境; 列出项目; 字符串描述; 长期权; 公共ListAdapter(上下文上下文、列表行项、字符串描述、长选项) { this.context=上下文; this.rowItem=rowItem; this.description=描述; this.option=选项; } @凌驾 public int g

这就是我填充我的
列表视图的方式:

这是一个场景:

1-创建两个阵列

2-创建RowItem类 3-创建ListAdapter
公共类ListAdapter扩展了BaseAdapter{
语境;
列出项目;
字符串描述;
长期权;
公共ListAdapter(上下文上下文、列表行项、字符串描述、长选项)
{
this.context=上下文;
this.rowItem=rowItem;
this.description=描述;
this.option=选项;
}
@凌驾
public int getCount(){
返回rowItem.size();
}
@凌驾
公共对象getItem(int位置){
返回rowItem.get(位置);
}
@凌驾
公共长getItemId(int位置){
返回rowItem.indexOf(getItem(position));
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
if(convertView==null){
LayoutInflater mInflater=(LayoutInflater)上下文
.getSystemService(活动.布局\充气机\服务);
convertView=mInflater.充气(R.layout.lv_箭头,空);
ImageView imgIcon=(ImageView)convertView.findViewById(R.id.imageView1);
TextView txtTitle=(TextView)convertView.findViewById(R.id.textView1);
IconRow row_pos=rowItem.get(位置);
//设置图像资源和标题
imgIcon.setImageResource(row_pos.getIcon());
setText(row_pos.getTitle());
}
返回视图;
}
4-创建行布局

5-在片段内创建列表
@覆盖
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment\u参数\u设置,容器,false);
lv_settings_1=(ListView)rootView.findviewbyd(R.id.lv_settings_1);
menutiles=getResources().getStringArray(R.array.array\u lv\u settings\u 1);
menuIcons=getResources().obtainTypedArray(R.array.arrow_图标);
menu_iconRow=新建ArrayList();
for(int i=0;i
问题
当使用此方法时,列表中最多有7项或更多项,它开始重复并填充错误。发生了什么事?

尝试更改适配器代码的这一部分:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        convertView = mInflater.inflate(R.layout.lv_arrow, null);
    }


    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
    TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

    IconRow row_pos = rowItem.get(position);
    // setting the image resource and title
    imgIcon.setImageResource(row_pos.getIcon());
    txtTitle.setText(row_pos.getTitle());

    return convertView;
}

convert视图可能与旧值一起重新使用

尝试更改适配器代码的这一部分:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        convertView = mInflater.inflate(R.layout.lv_arrow, null);
    }


    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
    TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

    IconRow row_pos = rowItem.get(position);
    // setting the image resource and title
    imgIcon.setImageResource(row_pos.getIcon());
    txtTitle.setText(row_pos.getTitle());

    return convertView;
}

convert视图可能与旧值一起重新使用

尝试更改适配器代码的这一部分:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        convertView = mInflater.inflate(R.layout.lv_arrow, null);
    }


    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
    TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

    IconRow row_pos = rowItem.get(position);
    // setting the image resource and title
    imgIcon.setImageResource(row_pos.getIcon());
    txtTitle.setText(row_pos.getTitle());

    return convertView;
}

convert视图可能与旧值一起重新使用

尝试更改适配器代码的这一部分:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        convertView = mInflater.inflate(R.layout.lv_arrow, null);
    }


    ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
    TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

    IconRow row_pos = rowItem.get(position);
    // setting the image resource and title
    imgIcon.setImageResource(row_pos.getIcon());
    txtTitle.setText(row_pos.getTitle());

    return convertView;
}
convert视图可能与旧值一起重新使用

修复: 3-创建ListAdapter

    public class ListAdapter extends BaseAdapter {

   ...

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                convertView = mInflater.inflate(R.layout.lv_arrow, null);

    }
            ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
            TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

            IconRow row_pos = rowItem.get(position);
            // setting the image resource and title
            imgIcon.setImageResource(row_pos.getIcon());
            txtTitle.setText(row_pos.getTitle());
        }

        return convertView;
    }
阅读有关ViewHolder的信息。

修复: 3-创建ListAdapter

    public class ListAdapter extends BaseAdapter {

   ...

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                convertView = mInflater.inflate(R.layout.lv_arrow, null);

    }
            ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
            TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

            IconRow row_pos = rowItem.get(position);
            // setting the image resource and title
            imgIcon.setImageResource(row_pos.getIcon());
            txtTitle.setText(row_pos.getTitle());
        }

        return convertView;
    }
阅读有关ViewHolder的信息。

修复: 3-创建ListAdapter

    public class ListAdapter extends BaseAdapter {

   ...

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                convertView = mInflater.inflate(R.layout.lv_arrow, null);

    }
            ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
            TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

            IconRow row_pos = rowItem.get(position);
            // setting the image resource and title
            imgIcon.setImageResource(row_pos.getIcon());
            txtTitle.setText(row_pos.getTitle());
        }

        return convertView;
    }
阅读有关ViewHolder的信息。

修复: 3-创建ListAdapter

    public class ListAdapter extends BaseAdapter {

   ...

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater mInflater = (LayoutInflater) context
                    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                convertView = mInflater.inflate(R.layout.lv_arrow, null);

    }
            ImageView imgIcon = (ImageView) convertView.findViewById(R.id.imageView1);
            TextView txtTitle = (TextView) convertView.findViewById(R.id.textView1);

            IconRow row_pos = rowItem.get(position);
            // setting the image resource and title
            imgIcon.setImageResource(row_pos.getIcon());
            txtTitle.setText(row_pos.getTitle());
        }

        return convertView;
    }

阅读有关ViewHolder的内容。

因为所有内容都在
if(convertView==null){
块中因为所有内容都在
if(convertView==null){
块中因为所有内容都在
if(convertView==null){
块中