Reputation: 165
if I try to set the checked state of a CheckBox it does not work, I have read many threads by others and all I could get is that its a different checkbox that is being returned every time but I'm setting this new checkbox so why its not being checked in my spinner?
classesName.setAdapter(new SpinnerAdapter() {
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public int getViewTypeCount() {
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
LayoutInflater inflater = Registeration.this.getLayoutInflater();
View spinView = inflater.inflate(R.layout.classes_registeration_ddl, null);
CheckBox rbtn = (CheckBox) spinView.findViewById(R.id.radioButtonClassesReg);
rbtn.setChecked(true);
return spinView;
}
@Override
public int getItemViewType(int arg0) {
return 0;
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public Object getItem(int arg0) {
return classesArr[arg0];
}
@Override
public int getCount() {
return classesArr.length;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = Registeration.this.getLayoutInflater();
View spinView = inflater.inflate(R.layout.classes_registeration_ddl, null);
CheckBox rbtn = (CheckBox) spinView.findViewById(R.id.radioButtonClassesReg);
rbtn.setChecked(true);
return spinView;
}
});
Upvotes: 5
Views: 714
Reputation: 1244
The reason for this is that android ListView's code runs after getDropDownView to keeps track of selected states. You can work around this with a custom CheckBox class which overrides isChecked and returns true/false based on the parents data.
Upvotes: 1