why spinner changing & Reset value on scrolling listview
why spinner changing & Reset value on scrolling listview
Task: I have an activity which has a list view there is some info of student and a status which is spinner in the list view.
Problem:
When i scroll list view the spinner value auto change the spinner did not hold the selected value its reset by scrolling list view.
If anyone know please suggest me solution or links which is useful. I shall be very thankful to him. I tried many solution but did not get out from this problem.
In the first image spinner value is present but when i scroll and come back to this again it auto change as you can see it is Absent now.
custom adopter:
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 class
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;
}
}
ok sir i am sending you link
– Adnan Khan
17 mins ago
i am not sir, please check the profile first Adman khan
– Rajshree Tiwari
16 mins ago
@RajshreeTiwari please chk my code i edit my question.
– Adnan Khan
3 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
what you tried at your end, please show your code
– Rajshree Tiwari
23 mins ago