javaandroidlistviewcustom-adapter

Why am I getting a different Sized list row while using a CustomListAdapter even though i tried giving a specific value to the custom list row


I have created a custom listView but when I run the code I get 1 row per screen. I have put the layout width and height of the parent layout in the listview_row.xml as match_parent and wrap_Content respectively.

this is the code for the listview_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/ll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/imageViewID"
        android:layout_width="112dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        app:srcCompat="@android:drawable/ic_menu_today" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <TextView
            android:id="@+id/nameTextViewID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/infoTextViewID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="18sp" />
    </LinearLayout>
</LinearLayout>

but after all rest coding, I get the output as i can see only one row a screen the 2nd row is far below

here I have scrolled a bit down and showed

Can anyone help me with this such that to display rows like a normal listView instead of getting 1 row per page?

I am new to this and thanks in advance.


Solution

  • Try changing it to this one:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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/ll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    
        <ImageView
            android:id="@+id/imageViewID"
            android:layout_width="112dp"
            android:layout_height="112dp"
            app:srcCompat="@android:drawable/ic_menu_today" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:orientation="vertical">
    
        <TextView
            android:id="@+id/nameTextViewID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="18sp" />
    
        <TextView
            android:id="@+id/infoTextViewID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textAlignment="center"
            android:textSize="18sp" />
    </LinearLayout>