In an Android Activity class which implements a ListView, I have an OnClickListener which I can't seem to get any data from the class. The class has Strings, Arrays, JSONObjects, any of which would be helpful if only they were accessible inside the OnClickListener function. How is this done? Also sorry Stackoverflow and everyone else because I can't seem to make "Class CompanyListActivity : AppCompatActivity() {" appear inside the code block. Just pretend it is there.
Class CompanyListActivity : AppCompatActivity() {
lateinit var arrCompany: Array<Array<String?>>
arrCompany = // some valid data...
var mListView = findViewById<ListView>(R.id.listviewCompanyListCompanies)
mListView.onItemClickListener = AdapterView.OnItemClickListener { _, _, index, _ ->
val intent = Intent (this@CompanyListActivity, CompanyActivity::class.java)
intent.putExtra("Response", arrCompany[index]) // no data in arrCompany
startActivity(intent)
}
Add a public Getter function to the Parent Activity class:
Then call it inside the OnClickListerner function: