sahobalar = ArrayList()
val sahoba1: TextView = findViewById(R.id.sahoba1)
val sahoba2: TextView = findViewById(R.id.sahoba2)
val sahoba3: TextView = findViewById(R.id.sahoba3)
// ...
// Initialize all the TextViews
sahobalar.add(sahoba1)
sahobalar.add(sahoba2)
sahobalar.add(sahoba3)
// ...
// Add all TextViews to the sahobalar list
sahobaInfos = ArrayList()
val sahobaInfo1: LinearLayout = findViewById(R.id.sahobaInfo1)
val sahobaInfo2: LinearLayout = findViewById(R.id.sahobaInfo2)
val sahobaInfo3: LinearLayout = findViewById(R.id.sahobaInfo3)
// ...
// Initialize all the LinearLayouts
sahobaInfos.add(sahobaInfo1)
sahobaInfos.add(sahobaInfo2)
sahobaInfos.add(sahobaInfo3)
// ...
// Add all LinearLayouts to the sahobaInfos list
for (i in sahobalar.indices) {
sahobaInfos[i].tag = i
sahobaInfos[i].setOnClickListener { view ->
val intent = Intent(this@MainActivity, InfoActivity::class.java)
intent.putExtra("id", view.tag as Int)
startActivity(intent)
}
}
}
private fun loadDataToView() {
controller = DataController.getInstance()
controller.loadData()
val sahobaList: ArrayList = controller.getListSahoba()
for (i in sahobalar.indices) {
val sahobaData: SahobaData = sahobaList[i]
val text: TextView = sahobalar[i]
text.text = sahobaData.name
}
}
}