Creating a Table view in Android using Recyclerview
While working on an Android App, there came a requirement to add Table View. I’ve tried several Table View Libraries, but found them too confusing to setup. And when I got a case where the text needs to be fit in, and rows needs to be in equal height when the text grows big, I’ve to rely on RecyclerView to implement my own TableView. So Here it goes.
Table View we are making is a RecyclerView, with a row Item populated. To make the row expanding based on the height of the content of the cell which has the biggest content (height).
Setting up Header And Cells in Adapter
In order to setup the cells and header, you need to make some modification in the adapter.
1. Add a null value as the first item, so that header will be counted.
2. If Position is zero, setup the viewHolder with the Title String values and set a different background drawable to make it stand out.
3. If position not zero, fill it with content values, and change the drawable.
Making the Table Scrollable
To make the RecyclerView scrollable horizontally, you can put the RecyclerView inside a horizontal scrollview also by adding property
Also when adding to the fragment, adding to the recyclerView the property android:nestedScrollingEnabled=”true”
I’m Planning to make a simple example with GIF Animations, and host it to GitHub. Comments are welcome on any issues that arises.