show data in table view in android

前端 未结 6 707
自闭症患者
自闭症患者 2020-12-01 15:21

I want to get data from database in my android table view.

Should I use loop? Is static good for this?

6条回答
  •  [愿得一人]
    2020-12-01 15:37

    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:

    Example

提交回复
热议问题