Q
Q
qqweer2020-07-17 19:46:00
Android
qqweer, 2020-07-17 19:46:00

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

1 answer(s)
D
Denis Zagaevsky, 2020-07-17
@hawkkiller

Change the value in the adapter and call notifyDatasetChanfed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question