Search code examples
androidlistviewexpandablelistviewmaster-detail

ListView only showing first result - only in mobile device : MasterDetail View


I have this problem in my detail view in my Master/Detail Template based app. im populating expandable list in detail view. it is working fine in tablet view. but in mobile device it is only showing me first result only. i even tried removing CollapsingToolbarLayout to make sure listview not getting block by any other scroll options. but i couldn't find the problem.

Setting up adapter

ArrayList<ClientList> clientLists = ClientList.getClientList(getActivity(), clientResult);
Log.e("Client","--"+clientLists.size()); //Im getting the list size as normal 
clientExpandableAdapter = new ClientExpandableAdapter(getActivity(), clientLists);
expandableListView.setAdapter(clientExpandableAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
    @Override
    public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
        return false;
    }
});

Detail view layout

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/item_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.xxx.xxx.ItemDetailFragment"
    android:textIsSelectable="true"
    android:paddingBottom="16dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:background="@drawable/bottom_border"
            android:id="@+id/mainViewHeader">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:id="@+id/titleHeader"
            android:text="Clients" />
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:id="@+id/titleCountHeader"
            android:text="Clients"
            />
        </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/mainViewHeader"
        android:id="@+id/backgroundView"
        android:background="@color/colorWhite">

            <ExpandableListView
                android:id="@+id/mainExpandableDatalist"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </ExpandableListView>

        </RelativeLayout>

</RelativeLayout>

Solution

  • In this type of issues many mistakes are possible according to me.

    1. You might have taken ScrollView as parent of listview which is not at all required.
    2. Height of ListView or custom ListView layout's root element could be match_parent | fill_parent that shows single item in whole screen.

    It will be better if you show layout files too.