Custom listview

Asked

Viewed 455 times

0

I am trying to make a Custom Listview. I have my XLM

<ListView
    android:id="@+id/listViewCliente"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal"
    tools:listitem="@layout/row_cliente"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Notice that there I put a tools: and pointed to another XML to get the custom style.

In the design tab it shows the correct and already customized listview. But when I install on my phone or emulator it shows the default list.

Has anyone ever gone through it? I have tried to uninstall and install again, but nothing.

  • Change the listitem for this and see if it works: tools:listitem="@layout/sample_list_item"

1 answer

1


To use a custom layout in Listview, you have to define a layout XML file representing a Listview line and write a custom Adapter for your list that will tell you how to place each data in the views of that XML. Finally, in Mainactivity, you will create an Object Array with the data you want to show in Listview and associate this Adapter to Listview by passing the Array and XML id as parameters to it.

An example: http://www.ezzylearning.com/tutorial/customizing-android-listview-items-with-custom-arrayadapter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.