android - 自定义 ArrayAdapter getView 提供了错误的位置

标签 android android-arrayadapter

所以我收到一个错误,因为我的 Custom ArrayAdapter getView 方法提供的位置超出了我的列表中的项目数。例如,当我有一个项目时,它会在我返回此 Activity 后返回位置 1。

编辑:

private class CustomAdapter extends ArrayAdapter<LinearLayout>{
    public CustomAdapter(Context context, int resources, List<LinearLayout> objects){
        super(context, resources, objects);
    }

    public View getView(int position, View convertView, ViewGroup parent){
        LinearLayout row;

        LayoutInflater mInflater = getLayoutInflater();
        if (convertView == null){
            row = getItem(position);
        }
        else{
            row = (LinearLayout) mInflater.inflate(R.layout.list_row, null);

            TextView name = (TextView) row.findViewById(R.id.text1);
            name.setText(settingList.get(position).name);

            TextView value = (TextView) row.findViewById(R.id.text2);
            value.setText(settingList.get(position).value);
        }

        return row;
    }
}

最佳答案

该位置应基于您在覆盖的 getCount() 方法中返回的任何内容。你在做什么?

关于android - 自定义 ArrayAdapter getView 提供了错误的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6049374/

相关文章:

java - 非常大的数字选择器

java.io.FileNotFoundException : This file can not be opened as a file descriptor; it is probably compressed

Android 在上传到服务器之前减小图像大小

android - 使用选择器和 isEnabled() 禁用 ListView 项

java - Android - 从 ArrayList 中删除项目

java - 如何在 ArrayAdapter 中为 ListView 使用多个 TextView ?

Android ListView - adapter.notifyDataSetChanged 和使用新适配器之间的区别

java - 无法实例化 Activity ...由 ClassNotFoundException 引起

android - 使用可用的 wifi 地址填充微调器

java - 更新适配器后 ListView 失去位置 listView.setAdapter(new MyAdapter(...))