I am making an app with kotlin, and I have two checkboxes, When I select the first checkbox, I would like 2 checkboxes to be automatically created in the next activity. if I select the second checkbox I would like 3 checkboxes to be created, and if I select the two checkboxes, I would like 5 checkboxes to be created in the next activity. Is that possible? and how. Thanks. This is my first activity.
listo = findViewById(R.id.button4) as Button
listo!!.setOnClickListener {
var lista= arrayListOf<Int>()
if(checkBox.isChecked){
lista.add(1)
}
if(checkBox2.isChecked){
lista.add(2)
}
val intent = Intent(this,MainActivity3::class.java)
intent.putExtra("check", lista)
startActivity(intent)
}
My second activity would like it to be something like this, but I'm sure what I tried can't.
texto3=findViewById(R.id.editTextDate)
val extras = intent.extras
val s = extras?.getIntegerArrayList("check")
var cantidad= s?.size
var i=0
while (i< cantidad!!){
when(s?.get(i)){
1->create(<CheckBox
android:text="@string/string_check1"
android:onClick="evento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/check+i"
android:layout_weight="1"
/>)
2->create(<CheckBox
android:text="@string/string_check1"
android:onClick="evento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/check+i"
android:layout_weight="1"
/>)
else-> println("ERROR")
}
i++
}
I would like the checkboxes to have the elements of my list as id.
Aucun commentaire:
Enregistrer un commentaire