Alamri
Alamri

Reputation: 2182

Show multi ListView in one screen

i have 2 ListView and each one get informations from a website databse.... everything is going fine, but what i want is to show the first listview then under it the second listview without setting a fixed height .. like the user should scrool to the end of first listview and then show the second listview without showing the scroller. here what I have done :

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

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

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <ListView
        android:id="@+id/secondlist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         >
     </ListView>
    </RelativeLayout>

</LinearLayout>

but the screen is not showing both even if i keep scrolling, only one listview ( the first ) is show up ... unless i give them fixed height eg android:layout_height="180dp" any ideas ?

Upvotes: 0

Views: 821

Answers (3)

Bhavesh Hirpara
Bhavesh Hirpara

Reputation: 22556

Can you please try this?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@+id/listView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="#C0C0C0" >
</LinearLayout>

<ListView
    android:id="@+id/listView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >
</ListView>

Upvotes: 0

buptcoder
buptcoder

Reputation: 2702

I have same issue before. Here are four solutions:

1.give the android:layout_weight = "1" for each listview so them can halve the screen.

2.put them in a tabview.

3.Merge two lists into one listview.

4.Use ExpandableListView

Upvotes: 0

Ameer Moaaviah
Ameer Moaaviah

Reputation: 1526

why dont you use ExpandableListView

Example 1

Example 2

Example 3

Upvotes: 0

Related Questions