Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RecyclerView - Layout Preview - How to Remove "Item 0, Item 1,... " text near Checkbox?

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>
like image 927
Laur Ivan Avatar asked Mar 15 '16 15:03

Laur Ivan


People also ask

What is RecyclerView LayoutManager?

A RecyclerView.LayoutManager implementation that lays out items in a grid for leanback VerticalGridView and HorizontalGridView . LinearLayoutManager. A RecyclerView.LayoutManager implementation which provides similar functionality to ListView .


1 Answers

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

like image 104
w33v1l Avatar answered Sep 18 '22 23:09

w33v1l