Creating the UI

In the created main_activity layout, we'll show a list of the user details where we show the name, email ID, and contact number of a user—we'll use ListView.

Here's the code of the mainActivity layout of the MainActivity class:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/user_title"
app:layout_constraintEnd_toEndOf="parent"
android:textStyle="bold"
android:padding="5dp"
android:gravity="center_horizontal"
android:textAppearance="?android:textAppearanceLarge"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ListView
android:id="@+id/displayList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />

</android.support.constraint.ConstraintLayout>

In this layout, we have one TextView and one ListView.

We'll use this ListView in the onResponse() function of MainActivity

We'll get the list and create a custom adapter to show the user list, as follows:

val adapter = UserListAdapter(this@MainActivity, 
response.body()//this is a arraylist
)

Here, we have a custom adapter where we'll send the context and the Array list of the users. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.158.36