monsterbrain
RecyclerviewTableViewAndroid
Kotlin

A sample Android Studio Project showing using a Recyclerview as a Table View.

Last updated Apr 24, 2026
91
Stars
20
Forks
2
Issues
0
Stars/day
Attention Score
23
Language breakdown
No language data available.
โ–ธ Files click to expand
README

TableView using Recyclerview (Android)

A sample Android Studio Project showing using a Recyclerview as a Table View.

How the Height of Row works

The Height of row is determined by the cell, which has maximum multiline content. In this sample that cell is given wrapcontent and other cells are given matchparent. I've got to find a way to dynamically check this later.

Upgraded to Kotlin (38% code reduction :))

(older java version can be found here

Here's the preview

TableView Demo Gif

Code Snippets

Here's the Recyclerview xml in the main layout.

width="matchparent" android:layoutheight="matchparent">

width="matchparent" android:layoutheight="wrapcontent" android:nestedScrollingEnabled="false" tools:listitem="@layout/tablelistitem" />

Here's the Recyclerview Adapter onBinding (all other stuffs are the same)

Kotlin Version

val rowPos = holder.adapterPosition

if (rowPos == 0) { // Header Cells. Main Headings appear here holder.itemView.apply { setHeaderBg(txtMovieName) txtMovieName.text = "Name" } } else { val modal = movieList[rowPos - 1]

holder.itemView.apply { setContentBg(txtMovieName) txtMovieName.text = modal.movieName } }

Click to see the example in Java.

@Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { RowViewHolder rowViewHolder = (RowViewHolder) holder;

int rowPos = rowViewHolder.getAdapterPosition();

if (rowPos == 0) { // Header Cells. Main Headings appear here rowViewHolder.txtRank.setBackgroundResource(R.drawable.tableheadercell_bg); rowViewHolder.txtMovieName.setBackgroundResource(R.drawable.tableheadercell_bg); rowViewHolder.txtYear.setBackgroundResource(R.drawable.tableheadercell_bg); rowViewHolder.txtCost.setBackgroundResource(R.drawable.tableheadercell_bg);

rowViewHolder.txtRank.setText("Rank"); rowViewHolder.txtMovieName.setText("Name"); rowViewHolder.txtYear.setText("Year"); rowViewHolder.txtCost.setText("Budget (in Millions)"); } else { MovieModal modal = movieList.get(rowPos-1);

// Content Cells. Content appear here rowViewHolder.txtRank.setBackgroundResource(R.drawable.tablecontentcell_bg); rowViewHolder.txtMovieName.setBackgroundResource(R.drawable.tablecontentcell_bg); rowViewHolder.txtYear.setBackgroundResource(R.drawable.tablecontentcell_bg); rowViewHolder.txtCost.setBackgroundResource(R.drawable.tablecontentcell_bg);

rowViewHolder.txtRank.setText(modal.getRank()+""); rowViewHolder.txtMovieName.setText(modal.getMovieName()); rowViewHolder.txtYear.setText(modal.getYear()+""); rowViewHolder.txtCost.setText(modal.getBudgetInMillions()+""); } }

@Override public int getItemCount() { return movieList.size()+1; // one more to add header row }

Motivation

While searching for TableView plugins, I found out that many of the Tableviews are really hard to setup and customize. So had to make one using Recyclerview, for adjusting the row height based on the content text.

Some Useful Tableview Plugins

TableRecycleView Plugin by HYY-yu

ยฉ 2026 GitRepoTrend ยท monsterbrain/RecyclerviewTableViewAndroid ยท Updated daily from GitHub