Basically, I have created an arrayList from the main activity class which goes like this:
val qrResultList = ArrayList<String>()
Now, when I press the button, it shall add a value on the array list:
qrResultList.add(textResult.value)
Now, I want to press another button that actually puts the qrResultList as a full arraylistvariable.
val intent = Intent (this@MainActivity, QRSessionFullList::class.java)
intent.putExtra("qrResultList", qrResultList) // push the whole qr result list to be hauled by the next activity.
startActivity(intent) // pushes the event to the qr list
Now, I want to display it in a listview kind of thing, and then made a for loop to access it:
val qrResultList = intent.getStringArrayExtra("qrResultList").toString() // coverts to array
for (item in qrResultList) {
val arrayAdapter:ArrayAdapter<String> = ArrayAdapter(
this, android.R.layout.simple_list_item_1,
qrResultList
)
qrlistview.adapter = arrayAdapter
qrlistview.setOnItemClickListener {
adapterView, view, i, l -> Toast.makeText(this, "Item Selected " + qrResultList[i],
Toast.LENGTH_LONG).show()
}
}
But it says the ArrayAdapter can not be called with the events supplied. Is there a way I can assign the values because this part:
val arrayAdapter:ArrayAdapter<String> = ArrayAdapter(
this, android.R.layout.simple_list_item_1,
qrResultList
)
it does not accept the qrResultList as an array 🙁