0

So I have a few arrays of data I would like to display in an activity without having like 15 text views with unique ids. Is there a code efficient way to make a Table layout or something like it where I could feed in data and it would automatically place it in there respective text views? Thanks!

Jared
  • 2,029
  • 5
  • 20
  • 39

1 Answers1

2

I think you can achieve that by using RecyclerView (with a GridLayoutManager). Have a look at this answer.

If there are only TextViews and you don't want a specific layout you can use SimpleAdapter, if you want to modify the layout you have to extend RecycleView.Adapter (there is an example in the answer above).

You can add/remove items into/from a List and use DiffUtil that

can calculate the difference between two lists and output a list of update operations that converts the first list into the second one.

There are a lot of tutorials about using this class. Have a look here or here.

Or you can use the notifyItemChanged() method:

If the list needs an update, call a notification method on the RecyclerView.Adapter object, such as notifyItemChanged(). The layout manager then rebinds any affected view holders, allowing their data to be updated.

LE: There are some libraries available. Here is a list:

  1. https://github.com/evrencoskun/TableView
  2. https://github.com/HYY-yu/TableRecyclerView
  3. https://github.com/Cleveroad/AdaptiveTableLayout
  4. https://github.com/celerysoft/TableFixHeaders
grrigore
  • 1,050
  • 1
  • 21
  • 39