My app has to display data in a 2D grid.The grid can have multiple rows and columns (10 by 10 or 100 by 44). And the grid must display the column and row names.
Basically I want something like the DataGridView from Windows Form and WPF.
Please provide help. Thank you.
You should use a TableLayout
, dynamically add TableRow
with as many TextView
s that corresponds to the columns that you wish to add. In order to make the grid look you should add a shape drawable as the background drawable of each TextView
with white lines in order to have cells.
Sample: in the layout.xml:
...
<TableLayout id="grid" *other properties*/>
...
a simple object Data that has all the necessary properties:
class Data {
ArrayList<Row> rows;
ArrayList<Column> column;
//or some other properties you might need
}
in the Activity
:
private void fillGrid(Data dat,) {
for(int i=0; i<dat.getRows().size(); i++) {
TableRow row = new TableRow(this);
//set row
for(int j=0; j<dat.getColumns().size(); j++) {
TextView actualData = new TextView(this);
//set properties
row.addView(actualData);
}
tableLayout.addView(row);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With