8

I have a RecyclerView where each list row item has a CheckBox. In the layout preview of the list row on its own, the Checkbox is shown correctly, with no text:

List row layout preview - screenshot

However, when I view the layout preview as part of the RecyclerView (using tools:listitem = "@layout/application_list_content"), I see unwanted sample texts like "Item 0", "Item 1", "Item 3", and so on:

RecyclerView layout preview - screenshot

Question: Is there a way to make Android Studio's Layout Preview not show the sample texts - "Item X" - and instead just display an empty string?

The code for the RecyclerView is:

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/application_list"
    android:name="com.laurivan.android.ApplicationListFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginEnd="?listPreferredItemPaddingRight"
    android:layout_marginStart="?listPreferredItemPaddingLeft"
    app:layoutManager="LinearLayoutManager"
    tools:context="com.laurivan.android.ApplicationListActivity"
    tools:listitem="@layout/application_list_content"/>

The item row has something like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="wrap_content"
                android:layout_height="@dimen/list_item_height_normal"
                android:orientation="horizontal"
    >

    <CheckBox
        android:id="@+id/app_checkBox"
        style="?android:attr/starStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_alignParentEnd="true"
        android:layout_margin="0dp"
        android:checked="false"
        android:padding="0dp"
        tools:text=""
        />

</RelativeLayout>
Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
Laur Ivan
  • 4,117
  • 3
  • 38
  • 62

1 Answers1

9

In case this helps anyone else, I resorted to using a zero-width whitespace character to do this, i.e. tools:text="&#8203;" in the layout of the Checkbox:

<CheckBox
    android:id="@+id/app_checkBox"
    style="?android:attr/starStyle"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_alignParentEnd="true"
    android:layout_margin="0dp"
    android:checked="false"
    android:padding="0dp"
    tools:text="&#8203;"
    />

More info: https://en.wikipedia.org/wiki/Zero-width_space

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
w33v1l
  • 91
  • 1
  • 3
  • 3
    Good answer. You can also use a space character: `tools:text=" "`, and it works on `RadioButton` as well. There is a similar bug report here: https://issuetracker.google.com/issues/63651166 but it's not the same problem. – Mr-IDE Dec 25 '19 at 10:47