eugene
eugene

Reputation: 41665

two listViews in one activity

I have two list views.

The problem I have is that screen scrolls until smaller(height) listview reaches the bottom.
How can I expand the containing view so that I can scroll to the bottom of longer listView?

I overloaded onScroll to scroll both list at the same time.

    public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {

        super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
        if (view.getChildAt(0) != null) {
            if (view.equals(m_lv1) ){
                m_lv2.setSelectionFromTop(view.getFirstVisiblePosition(),
                    view.getChildAt(0).getTop());
            } else if (view.equals(m_lv2) ){
                m_lv1.setSelectionFromTop(view.getFirstVisiblePosition(),
                    view.getChildAt(0).getTop());
            }
        }
    }


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

  <ListView
      android:id="@+id/list_view_left"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:scrollbars="none"  
      android:layout_weight="1" >
  </ListView>

  <ListView
      android:id="@+id/list_view_right"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1" >
  </ListView>
</LinearLayout>

Upvotes: 2

Views: 2131

Answers (2)

Dipak Keshariya
Dipak Keshariya

Reputation: 22291

Use below XML code instead of your code.

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

  <ListView
      android:id="@+id/list_view_left"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1" >
  </ListView>

  <ListView
      android:id="@+id/list_view_right"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1" >
  </ListView>
</LinearLayout>

Upvotes: 1

Mehul Ranpara
Mehul Ranpara

Reputation: 4255

you have to set the height of the listview...like.

<ListView
      android:id="@+id/list_view_left"
      android:layout_width="fill_parent"
      android:layout_height="120dp"
      android:scrollbars="none"  
      android:layout_weight="1" >
  </ListView>

  <ListView
      android:id="@+id/list_view_right"
      android:layout_width="fill_parent"
      android:layout_height="120dp"
      android:layout_weight="1" >
  </ListView>

Upvotes: 2

Related Questions