samedi 6 juillet 2019

Weird bug don't let me fill my data class object

I have debugged the app entirely, rechecked all and I'm having a really weird issue that does not let me assign values to the object itself.

I have a Fragment that implements the onClickListener for CheckBoxs click, I don't want to do this with an interface within my Activity since I dont want to mix up logic of different fragments there.

So I decided to do it this way and handle all the CheckBoxes logic inside my Fragment.

Fragment

class InfoTecnicaFragment : Fragment(), view.onClickListener {

    private lateinit var infoTecCheckObj: InfoTecChecks

    override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            infoTecCheckObj = InfoTecChecks()
        }

        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {

            val rootView = inflater.inflate(R.layout.fragment_infoT, container, false)

            val chck1 = rootView.findViewById<CheckBox>(R.id.chk_1)
            val chck2 = rootView.findViewById<CheckBox>(R.id.chk_2)
            val chck3 = rootView.findViewById<CheckBox>(R.id.chk_3)

            chck1.setOnClickListener(this)
            chck2.setOnClickListener(this)
            chck3.setOnClickListener(this)

            return rootView
        }


         override fun onClick(v: View?) {
                if (v is CheckBox) {
                    val checked = v.isChecked
                    when (view?.id) {

                        R.id.chk_1 -> {
                            infoTecCheckObj.check_1 = checked
                        }

                        R.id.chk_2 -> {
                            infoTecCheckObj.check_2 = checked
                        }

                        R.id.chk_3 -> {
                            infoTecCheckObj.check_3 = checked
                        }
                    }
                }

                Log.d("CheckObj: ","$infoTecCheckObj")

            }

Now, the clicks are working , I put a break point in my onClick and it works with all the checks, also the check boolean value is changed and also registered, but for some reason this

  R.id.chk_1 -> {
                            infoTecCheckObj.check_1 = checked
                        }

                        R.id.chk_2 -> {
                            infoTecCheckObj.check_2 = checked
                        }

                        R.id.chk_3 -> {
                            infoTecCheckObj.check_3 = checked
                        }

for any check that I do , it does not update my infoTecCheckObj and I really dont know why

Data class

data class InfoTecChecks(var check_1: Boolean = false,
                             var check_2: Boolean = false,
                             var check_3: Boolean = false)

My infoTecCheckObj after I check any of those checks prints all 3 false instead of printing true for any one that I click.

I dont know if this is a bug or an error from my end

Aucun commentaire:

Enregistrer un commentaire