ListView

ListView

  • A ListView is a type of AdapterView that displays a vertical list of scroll-able views and each view is placed one below the other.
  • setAdaptor() method conjoins an adapter with the list.
  • Android ListView is a ViewGroup that is used to display the list of items in multiple rows and contains an adapter that automatically inserts the items into the list.
  • The main purpose of the adapter is to fetch data from an array or database and insert each item that placed into the list for the desired result.
  • So, it is the main source to pull data from strings.xml file which contains all the required strings in Java or XML files.

XML Attributes of ListView

Attribute
Description
android:divider
A color or drawable to separate list items.
android:dividerHeight
Divider’s height.
android:entries
Reference to an array resource that will populate the ListView.
android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each footer view.
android:headerDividersEnabled
When set to false, the ListView will not draw the divider before each header view.

XML for Linear Layout

<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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:orientation="vertical"> <ListView android:id="@+id/userlist" android:layout_width="match_parent" <!-- to remove divider -- android:divider="@null" android:layout_height="wrap_content" > </ListView> </LinearLayout>
 

More connectivity in Kotlin File:

ListView
ListView