Answer the question
In order to leave comments, you need to log in
How to change cell text in GridView?
In general, I have a GridView with the id gridView. Simply, when you click on an element, the text of the element should be replaced by its coordinates. Here is the code
var data = MutableList(31, {x->"$x"})
val adapter = ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data)
gridView.adapter = adapter
gridView.onItemClickListener = AdapterView.OnItemClickListener { p0, p1, p2, p3 ->
val COLUM_NUM = gridView.numColumns
var selectedItem = p0?.getItemAtPosition(p2).toString()
var col :Int= (selectedItem.toInt() % COLUM_NUM)+1
var row :Int= (selectedItem.toInt() / COLUM_NUM)+1
Toast.makeText(this@MainActivity, "$row,$col", Toast.LENGTH_SHORT).show() - Создал просто для проверки, всё работает.
}
Answer the question
In order to leave comments, you need to log in
Change the value in the adapter and call notifyDatasetChanfed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question