What is a tools:itemCount equivalent for ExpandableListView?

Viewed 585

RecyclerView offers a convenient way to preview the layout in Android Studio's tab called Design:

tools:itemCount

Is there any equivalent for ExpandableListView?

I assume the answer is "no" because I found that a different tool, tools:listitem does work for ExpandableListView. I believe that's explained by its documentation, "Intended for: <AdapterView> (and subclasses like <ListView>)".

1 Answers

Yes, you are right. Each tools: attribute belongs to different class.

You could integrate these two attributes like below.

The main layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    tools:context=".MainActivity">

    <ExpandableListView
        android:id="@+id/expandableListView"
        tools:listitem="@layout/sample_list_item" //notice this line
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:indicatorLeft="?android:attr/expandableListPreferredItemIndicatorLeft"
        android:divider="@android:color/darker_gray"
        android:dividerHeight="0.5dp" />

</RelativeLayout>

The sample_list_item layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:itemCount="3"  //notice this line
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>

Now you will see in preview as below fig: enter image description here

notice there are three items shown.

Related