I want to get data from database
in my android table view
.
Should I use loop? Is static good for this?
I see this post is pretty old, but if someone else is facing also the issue to display custom data in a Table in Android, I would like to offer my TableView as possible solution to do so.
So you do not care about how to fill the data to your table, you can simply create a custom adapter for the data you want to show (like we already know in Android from views like the ListView).
our code will look like this:
List myData = new ArrayList<>();
myData.add(new Flight(...));
myData.add(new Flight(...));
myData.add(new Flight(...));
TableView table = findViewById(R.id.table);
table.setHeaderAdapter(new SimpleHeaderAdapter("Time", "Airline", "Flight", "Destination"));
table.setDataAdapter(new FlightDataAdapter(myData));
The result could look like this: