Skip to content
A sample Android Studio Project showing using a Recyclerview as a Table View.
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app Few Comments added ... Dec 22, 2018
.gitignore Initial commit Aug 29, 2018
README.md Update README.md Dec 22, 2018
build.gradle Initial commit Aug 29, 2018
gradle.properties Initial commit Aug 29, 2018
gradlew Initial commit Aug 29, 2018
gradlew.bat Initial commit Aug 29, 2018
settings.gradle Initial commit Aug 29, 2018
tableview_demo.gif Added demo gif Aug 29, 2018

README.md

TableView using Recyclerview (Android)

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

Here's the preview

TableView Demo Gif

Code Snippets

Here's the Recyclerview xml in the main layout.

<!-- Table View-->
<HorizontalScrollView
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerViewMovieList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:nestedScrollingEnabled="false"
    tools:listitem="@layout/table_list_item" />

</HorizontalScrollView>

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

@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.table_header_cell_bg);
        rowViewHolder.txtMovieName.setBackgroundResource(R.drawable.table_header_cell_bg);
        rowViewHolder.txtYear.setBackgroundResource(R.drawable.table_header_cell_bg);
        rowViewHolder.txtCost.setBackgroundResource(R.drawable.table_header_cell_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.table_content_cell_bg);
        rowViewHolder.txtMovieName.setBackgroundResource(R.drawable.table_content_cell_bg);
        rowViewHolder.txtYear.setBackgroundResource(R.drawable.table_content_cell_bg);
        rowViewHolder.txtCost.setBackgroundResource(R.drawable.table_content_cell_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

You can’t perform that action at this time.