Too many views in a scrollview


I need some good advice please. I have a scrollview with a TableLayout. The table consists of 5 columns so every TableRow consists of 5 Textviews. It's working very well, but I would like to add more TableRows, and since I'm using:

private ActivityMainBinding binding;

there is a limit how many views it can handle. There must be a better way constructing a scrollable table with 5 columns that doesn't consume that many views?

I learned java programming by myself, so I know there is a lot of stuff I don't know. Maybe someone can point me in the right direction?

activity_main.xml:
            <ScrollView
                android:id="@+id/scrollview"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="@dimen/weight_main_scroll_table"
                android:layout_marginStart="0dp"
                android:layout_marginTop="0dp"
                android:layout_marginEnd="0dp"
                android:layout_marginBottom="0dp"
                android:background="@drawable/border_table"
                android:fillViewport="true"
                android:paddingStart="2dp"
                android:paddingTop="2dp"
                android:paddingEnd="2dp"
                android:paddingBottom="2dp"
                tools:ignore="SpeakableTextPresentCheck">
                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="0dp"
                    android:layout_marginTop="0dp"
                    android:layout_marginEnd="0dp"
                    android:layout_marginBottom="0dp"
                    android:paddingStart="0dp"
                    android:paddingTop="0dp"
                    android:paddingEnd="0dp"
                    android:paddingBottom="0dp"
                    android:visibility="visible">
                    <TableRow
                        android:id="@+id/tablerow_0"
                        style="@style/tablerow_style"
                        android:tag="0"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_0"
                            style="@style/table_textview_style_col0"
                            tools:ignore="TextContrastCheck" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_1"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_2"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_3"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_4"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_1"
                        style="@style/tablerow_style"
                        android:tag="1"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_5"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_6"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_7"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_8"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_9"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_2"
                        style="@style/tablerow_style"
                        android:tag="2"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_10"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_11"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_12"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_13"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_14"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_3"
                        style="@style/tablerow_style"
                        android:tag="3"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_15"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_16"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_17"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_18"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_19"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_4"
                        style="@style/tablerow_style"
                        android:tag="4"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_20"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_21"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_22"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_23"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_24"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_5"
                        style="@style/tablerow_style"
                        android:tag="5"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_25"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_26"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_27"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_28"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_29"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_6"
                        style="@style/tablerow_style"
                        android:tag="6"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_30"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_31"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_32"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_33"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_34"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_7"
                        style="@style/tablerow_style"
                        android:tag="7"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_35"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_36"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_37"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_38"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_39"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_8"
                        style="@style/tablerow_style"
                        android:tag="8"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_40"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_41"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_42"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_43"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_44"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_9"
                        style="@style/tablerow_style"
                        android:tag="9"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_45"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_46"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_47"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_48"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_49"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_10"
                        style="@style/tablerow_style"
                        android:tag="10"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_50"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_51"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_52"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_53"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_54"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_11"
                        style="@style/tablerow_style"
                        android:tag="11"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_55"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_56"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_57"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_58"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_59"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_12"
                        style="@style/tablerow_style"
                        android:tag="12"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_60"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_61"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_62"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_63"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_64"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_13"
                        style="@style/tablerow_style"
                        android:tag="13"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_65"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_66"
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_68"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_69"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_14"
                        style="@style/tablerow_style"
                        android:tag="14"
                        tools:ignore="TouchTargetSizeCheck">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_70"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_71"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_72"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_73"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_74"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_15"
                        style="@style/tablerow_style"
                        android:tag="15">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_75"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_76"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_77"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_78"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_79"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_16"
                        style="@style/tablerow_style"
                        android:tag="16">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_80"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_81"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_82"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_83"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_84"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_17"
                        style="@style/tablerow_style"
                        android:tag="17">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_85"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_86"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_87"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_88"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_89"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_18"
                        style="@style/tablerow_style"
                        android:tag="18">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_90"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_91"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_92"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_93"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_94"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                    <TableRow
                        android:id="@+id/tablerow_19"
                        style="@style/tablerow_style"
                        android:tag="19">
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_95"
                            style="@style/table_textview_style_col0" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_96"
                            style="@style/table_textview_style_col1" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_97"
                            style="@style/table_textview_style_col2" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_98"
                            style="@style/table_textview_style_col3" />
                        <androidx.appcompat.widget.AppCompatTextView
                            android:id="@+id/table_textview_99"
                            style="@style/table_textview_style_col4" />
                    </TableRow>
                </TableLayout>
            </ScrollView>

enter image description here

0
Mar 20 at 5:57 PM
User AvatarTomas F.
#java#android#scrollview#tablelayout

Accepted Answer

Use a RecyclerView. It will handle the scrolling, and it will only take 5*N views, where N is the number of rows visible on screen, no matter how many rows there actually are. It does that by recycling the views- remapping what rows are displayed in the same physical set of views.

User AvatarGabe Sechan
Mar 20 at 6:08 PM
1