为什么微调器更改和重置滚动列表视图上的值

时间:2018-07-31 05:55:27

标签: java android listview android-spinner

任务:
我有一个活动,该活动具有一个列表视图,其中包含一些学生信息,并且该状态在列表视图中处于旋转状态。

问题:
当我滚动列表视图时,微调器的值会自动更改,微调器没有保持选定的值,而是通过滚动列表视图进行重置。

如果有人知道,请给我建议解决方案或有用的链接。我将非常感谢他。我尝试了许多解决方案,但没有摆脱这个问题。

在第一个图像微调器中存在值,但是当我滚动并再次返回到该值时,它会自动更改,如您所见,它现在不存在。

自定义采用者:

public class PersonalListAdapter extends ArrayAdapter<student> {

    Context mCtx;
    int mResource;

    static class ViewHolder {
        TextView id;
        TextView name;
        TextView f_name,rollno;
        Spinner status;
    }

    public PersonalListAdapter(@NonNull Context mCtx, int resource, @NonNull ArrayList<student> objects) {
        super(mCtx, resource, objects);
        this.mCtx = mCtx;
        mResource = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        final String id = getItem(position).getId();
        final String rollno = getItem(position).getRollno();
        final String stu_name = getItem(position).getName();
        final String f_name = getItem(position).getFname();
        final  String status = getItem(position).getStatus();

        Log.i("djajd",id);

        final View result;
        final ViewHolder holder;

        student student = new student(id,rollno,stu_name,f_name,status);
        LayoutInflater inflater = LayoutInflater.from(getContext());

        if(convertView == null)
        {
            convertView = inflater.inflate(mResource,parent,false);

            holder = new ViewHolder();
            holder.id = (TextView) convertView.findViewById(R.id.student_id);
            holder.rollno = (TextView) convertView.findViewById(R.id.student_rollno);

            holder.name = (TextView) convertView.findViewById(R.id.student_name);
            holder.f_name = (TextView) convertView.findViewById(R.id.father_name);

//            holder.st = (EditText) convertView.findViewById(R.id.status);
            holder.status = (Spinner) convertView.findViewById(R.id.status_spinner);
//            holder.status.setTag(position);


            result = convertView;

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

        holder.id.setText(id);
        holder.rollno.setText(rollno);
        holder.name.setText(stu_name);
        holder.f_name.setText(f_name);
//holder.status.setOnItemSelectedListener(status);

        return convertView;
    }
}

Arraylist类
student.java

public class student {

    String id;

    String rollno;
    String name;
    String fname;
    String status;


    public student(String id, String rollno,String name,String fname, String status) {
        this.id = id;

        this.rollno = rollno;
        this.name = name;
        this.fname = fname;
        this.status = status;

    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }



    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }


    public String getRollno() {
        return rollno;
    }

    public void setRollno(String rollno) {
        this.rollno = rollno;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }
}

1 个答案:

答案 0 :(得分:0)

只需在您的适配器类中覆盖它

@Override
    public int getViewTypeCount() {

        return getCount();
    }

    @Override
    public int getItemViewType(int position) {

        return position;
    }