问题
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