how to display 2D array in gridlayout

浪子不回头ぞ 提交于 2019-12-31 04:10:12

问题


I have Array [] [] myArray = new Array [5] [5], or Array [] [] myArray = new Array [7] [9], or new Array [12] [13]

I want to display the array in GridLayout. I found many examples but there is not a 2D array.

Tell me I should extend BaseAdapter? I do not know about how to solve this problem


回答1:


Simple thing you can do is, you can convert 2D array to a simple 1D array (using a for loop) and proceed as usual. And if you need to set the items dynamically (I mean, if you do not know the dimensions of the array before hand), then you have use the setColumnCount() to set the number of columns you need (5,9,13 in your examples). You don't have to wo0rry about the number rows as Android takes care of the rows. And yes, you should use BaseAdapter.



来源:https://stackoverflow.com/questions/12805040/how-to-display-2d-array-in-gridlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!