Android Spinner with CheckBox setChecked (true) not working

If I try to set the checked state of the CheckBox, this will not work, I read a lot of streams by others, and all I could get is that its new checkbox is returned every time, but I set this new checkbox, so why it is not checked for my counter?

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; } }); 
+4
source share
1 answer

The reason for this is that the ListView android code runs after getDropDownView to track selected states. You can get around this with the special CheckBox class, which overrides isChecked and returns true / false based on parent data.

0
source

All Articles