Tools namespace android listitem

8k views Asked by At

I'm trying to use the "tools" namespace feature in Android Studio. I'm trying to populate the ListView with dummy list items, for design purposes. The link here says the tools:listitem="@android:layout/<filename>" should do.

But for some reason, Android Studio keeps showing Layout android:<filename> does not exist. I'm trying to find a solution for it, so I don't have to run my app again and again with dummy values for testing.

I might be overlooking something very foolish, so forgive me. Here is what I have for now:

<ListView
    android:id="@+id/controllerProfiles"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="20dp"
    tools:listitem="@android:layout/profiles_list_item"/>

And I have a file profiles_list_item.xml under res/layout. Any suggestions or alternatives?

2

There are 2 answers

2
Mohammad Rahchamani On

you should change the following line :

tools:listitem="@android:layout/profiles_list_item"

to this :

tools:listitem="@layout/profiles_list_item"

with @android you say that you want to use a layout from android resources but your layout is in your own project files.

0
Cristan On

tools:listitem doesn't work with ListViews in Android Studio 2.2. This is a known bug. I've tested this in Android Studio 2.3 beta 1 and it is fixed here.

You can also move from ListView to RecyclerView as this bug doesn't occur at RecyclerViews.