jeudi 12 novembre 2015

Checkbox unchecks automatically

I am using the checkbox of the Material Design library by navasmdc.

When the fragment with the checkbox is loaded the checkbox gets checked (thats correct) but then it immediately gets unchecked (that's not what I want to)

I have put it into a recycler view item. So I set the checkbox inside the onBindViewHolder like that:

   @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        ReviewItem current = data.get(position);

        switch (holder.getItemViewType()) {

            case TYPE_SIMPLE:
                ViewHolderSimple simpleViewHolder = (ViewHolderSimple) holder;

                simpleViewHolder.title.setText(current.getTitle());
                simpleViewHolder.subtitle.setText("Wert: " + valuesOfMaschine.get(position));

                simpleViewHolder.image.setImageResource(R.drawable.ic_starticon);

                if(Integer.parseInt(valuesOfMaschine.get(position)) == 0)
                {
                    //simpleViewHolder.checkbox.setChecked(false);
                } else if(Integer.parseInt(valuesOfMaschine.get(position)) == 1){
                    simpleViewHolder.checkbox.setChecked(true);
                }

                break;

            case TYPE_DETAILED:
                ViewHolderDetailed detailedViewHolder = (ViewHolderDetailed) holder;

                detailedViewHolder.title.setText(current.getTitle());
                detailedViewHolder.subtitle.setText("Wert: " + valuesOfMaschine.get(position));

                detailedViewHolder.image.setImageResource(R.drawable.ic_starticon);

                detailedViewHolder.slider.setValue(Integer.parseInt(valuesOfMaschine.get(position)));

                break;
        }
    }

I see no part in my code that should be able to uncheck the checkbox again...

the xml of my checkbox:

 <RelativeLayout xmlns:android="http://ift.tt/nIICcg"
                    xmlns:materialdesign="http://ift.tt/GEGVYd"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    >
                    <com.gc.materialdesign.views.CheckBox
                        android:id="@+id/review_item_checkbox_simple"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:background="#1E88E5"
                        />

                </RelativeLayout>

Do I miss something ?




Aucun commentaire:

Enregistrer un commentaire