Search code examples
androidlistviewandroid-listviewandroid-custom-view

How to Implement Multiple List view one below the other without dividing the ActivityScreen in android


I am using 3 ListViews one below the other in a same Activity, But I can't see my third list view, and my second listview scrolls within itself, I need all the three list view to be scrolled in a single page one after the other. If I use the android:layout_weight="1" attribute, it shows all the list view by dividing the page, but I don't want to divide the activity screen, but to show all the list view one after the other.

Could anyone would guide me for the same, belopw is my xml layout which includes those three listviews:-

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ListView
        android:id="@+id/listTopTenBatsmans"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

    <ListView
        android:id="@+id/listTopTenBowlers"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

    <TextView
        android:id="@+id/tSometextField"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Fall of Wickets"
        android:textColor="@color/red"
        android:textSize="18sp"
        android:typeface="sans"
        android:textStyle="bold"
        android:background="#ffdfe5"
        android:paddingLeft="5dp" />

    <ListView
        android:id="@+id/listTopTenFielders"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

</LinearLayout>

In the above XML the first list is appers with some 10 fields in it populated as per my adapter view and the seconds is also appears with some 10 list field as per populated by adapter, but it scrolls in itself and where as the textview and list view is not appered, and if I use the android:layout_weight="1" attribute then It shows all the 3 listvies and the textview by dividing the activity screen, But I need one after the other.

Scenerio:-

ListView1
Element1    Ele1    E1
Element2    Ele2    E2
Element3    Ele2    E3
Element4    Ele4    E4
Element5    Ele5    E5
Element6    Ele6    E6
Element7    Ele7    E7
Element8    Ele8    E8
Element9    Ele9    E9
Element10   Ele10   E10

ListView2
Item1   It1 I1
Item2   It2     I2
Item3   It2     I3
Item4   It4     I4
Item5   It5     I5
Item6   It6     I6
Item7   It7 I7
Item8   It8 I8
Item9   It9     I9
Item10  It10    I10

SomeTextView
Listview3
Source1     Sou1    S1
Source2     Sou2    S2
Source3     Sou2    S3
Source4     Sou4    S4
Source5     Sou5    S5
Source6     Sou6    S6
Source7     Sou7    S7
Source8     Sou8    S8
Source9     Sou9    S9
Source10    Sou10   S10

Solution

  • As per earlier comment, you have several options:

    If you already have three ListViews and adapters set up, the quickest solution is to go with MergeAdapter. The more modern approach would be to trade in your current implementation for a RecyclerView, but that will probably mean some more serious code changes.