Solution 1 :
Use findViewById()
method to get view by id and check its state:
val array = arrayOf(arrayOf(R.id.Pencilbox, 5), arrayOf(R.id.Penbox, 6), arrayOf(R.id.Notebookbox, 10))
// in Activity
if (findViewById<CheckBox>(array[0][0]).isChecked) {...}
// in Fragment
if (view?.findViewById<CheckBox>(array[0][0])?.isChecked == true) {...}
Problem :
I have a checkbox with id: Pencilbox
. Now I have an array in which the first column contains the name of objects, names are equal to their checkbox id, and the second column is the price of them. so
Array:
Pencil 5
Pen 6
Notebook 10
Now I want to find the price of objects that the user wants. So normally I have to use:
if (Pencilbix.ischecked) {...}
But now, I want to use the first column of the array (as the string is equal to the checkbox id) instead of checkbox id, or:
if (Array[0][0].toString.ischecked) {...}
But it is wrong.
Any Idea?
Comments
Comment posted by Reihaneh Kouhi
What if I have to read the array from a csv file? In practice, my array is a big dataset with 9 columns.
Comment posted by Reihaneh Kouhi
Also, when I use your method, I got the error: array[0][0] should be in Int
Comment posted by Sergio
If you use android please add appropriate tags to your question.
Comment posted by Sergio
You get the error bcz
Comment posted by Reihaneh Kouhi
Great thanks. The guy who corrected my question, deleted the information corresponding to android. I had told that I am using android, kotlin,