im getting error while putting a vertical list view to a horizontal list view, something similar to https://appsandbiscuits.com/listview-tutorial-android-12-ccef4ead27cc it was to create a notes app to get title and content in every list entry.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:background="@drawable/kkkkk"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/listViewId"
android:layout_width="380dp"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="171dp"
android:layout_marginEnd="14dp"
android:layout_marginBottom="98dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />
<LinearLayout
android:id="@+id/verticalLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView1"
android:text="Title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/textView2"
android:text="Title"/>
</LinearLayout>
</ListView>
<Button
android:id="@+id/add_note"
android:layout_width="65dp"
android:layout_height="63dp"
android:layout_marginStart="166dp"
android:layout_marginTop="19dp"
android:layout_marginEnd="180dp"
android:layout_marginBottom="15dp"
android:alpha="0"
android:onClick="buttonPressed"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/listViewId" />
</androidx.constraintlayout.widget.ConstraintLayout>
i'm new to android development and it would really appreciate the help
In Android, you cannot direct add child view inside the ListView
directly. In your case, you are adding ImageView
and LinearLayout
as direct children of ListView
. Due to this, you are getting a Runtime exception. (Ref: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/widget/AdapterView.java;l=488 )
In Android, you are supposed to use adapter to add view inside ListView
or RecyclerView
. I would suggest you to look into Video tutorials instead of blog posts, since blog posts are super confusing about which code goes where.
只需使用 LinearLayout 而不是 ListView (我相信这是一个错字)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.