Search code examples
androidlistviewadapter

multiple HorizontalListView using same adapter?


I am using two HorizontalListView with same adapter.But only one HorizontalListView is visible ,i Can't figure out what I am doing wrong.

My Activity onCreate method:

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.books_library);
            ScienceBooks = (HorizontalListView) findViewById(R.id.ScienceBooks);
        FictionBooks = (HorizontalListView) findViewById(R.id.FictionBooks);
        adapter = new BookAdapter(BooksLibrary.this, 1, images);
        adapter1 = new BookAdapter(BooksLibrary.this, 1, images);
        ScienceBooks.setAdapter(adapter);
        FictionBooks.setAdapter(adapter1);
    }

books_library.xml

<?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" >


    <com.devsmart.android.ui.HorizontalListView
        android:id="@+id/ScienceBooks"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         />

    <com.devsmart.android.ui.HorizontalListView
        android:id="@+id/FictionBooks"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Solution

  • This is a known bug if your set the wrap_content constant as the HorizontalScrollView height. Until this bug is fixed, you can use a temporary solution by defining an absolute height for the HorizontalScrollView like this android:layout_height="220dp (any height will do of course). Using the layout_weight attribute instead should work too.