mercredi 3 août 2016

how to make a dual type of selection in listview in android

I know the question is not correct but i don't know what term is use for my question.

I have two types of question in my quiz, multiple choice and single choice.

What i use

I am using a ListView for showing answers and from backend i got parameter either

    "optiontype"="multiple"

or

    "optiontype"="single"

i don't know how to make a ListView with two type of selections. i can make it either single choice or multiple choice. i am using this from a stackoverflow answer.

     int position;
     if(position == selected_position) {
                     optionValue = galleryItems.get(position).getOptionValue();
                     holder.cbCheck.setChecked(true);
                    } else {
                        holder.cbCheck.setChecked(false);
                    }

                 holder.cbCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            if (isChecked == true)  {
                                selected_position =  position;
                            } else {
                                 selected_position = -1;
                                holder.cbCheck.setChecked(false);
                            }
                           // getProduct((Integer) buttonView.getTag()).box = isChecked;
                            notifyDataSetChanged();
                        }
                    });

question is how do i code for multiple choice question. also i need to disable the button if none is checked or selected.




Aucun commentaire:

Enregistrer un commentaire