Java 如何将具有特定视图的Linearlayout创建为另一个Linearlayout中的项目(任务)?

Java 如何将具有特定视图的Linearlayout创建为另一个Linearlayout中的项目(任务)?,java,android,android-studio,android-layout,android-intent,Java,Android,Android Studio,Android Layout,Android Intent,一周前,我开始了我的待办事项列表应用程序项目,我学到了很多。我想知道一个我找不到的具体案例 案例:我尝试将Linearlayout类型的“布局项”创建为任务,其中包含特定视图,如另一个Linearlayout中的“任务名称、任务描述、时间、删除按钮”。但问题是,第一个线性布局的视图都在其内部有一个特定的位置。我想保留视图的位置。如何将这种布局创建为项目 另一个简短的问题:当我创建这个布局时,如何以编程方式删除它 在这里,您可以找到我创建的设计以及“布局项”(任务)的确切外观 您可以使用如下所述

一周前,我开始了我的待办事项列表应用程序项目,我学到了很多。我想知道一个我找不到的具体案例

案例:我尝试将Linearlayout类型的“布局项”创建为任务,其中包含特定视图,如另一个Linearlayout中的“任务名称、任务描述、时间、删除按钮”。但问题是,第一个线性布局的视图都在其内部有一个特定的位置。我想保留视图的位置。如何将这种布局创建为项目

另一个简短的问题:当我创建这个布局时,如何以编程方式删除它

在这里,您可以找到我创建的设计以及“布局项”(任务)的确切外观


您可以使用如下所述的RecyclerView:


如果Ahmed是正确的,您将使用回收器并创建一个具有以下内容的视图:任务名称、任务描述、时间、删除按钮。然后,您可以通过编辑包含项目的数组来删除和添加项目


下面是一个简单的回收商示例:

但问题是什么?这是一种布局,您可以在RecyclerView中为每个项目使用。我想知道的是,如何使用预览图像中手动创建的视图以编程方式创建Linearlayout。我阅读了文档,并了解了如何使用RecyclerView。非常感谢你,艾哈迈德。我只想知道一件事(也许是我自己发现的):如何在recyclerview中实现日期文本视图,并根据给定的日期值对所有任务进行排序?我想动态创建新的日期文本视图,例如,当我创建一个日期不在任务列表中的新任务时。检查这个答案,它显示了如何使用比较器的实现,并使用它对RecyclerView的适配器中的项目列表进行排序:这个:还记得调用上的数据更改通知方法每当一个或多个任务的日期发生更改时,适配器就会启动,以便recycler视图将这些更改应用于UI。
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:background="#eeeeee"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="300dp"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/fira_sans_extra_condensed_semibold"
                    android:text="Task1"
                    android:textColor="@color/Task_Name"
                    android:textSize="16sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/textView11"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/fira_sans_condensed_light"
                    android:text="Description1 - I want to create a great todo list app :)"
                    android:textSize="14sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <TextView
                android:id="@+id/textView111"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:fontFamily="@font/fira_sans_condensed_light"
                android:gravity="end"
                android:text="9am"
                android:textStyle="bold" />

            <ImageButton
                android:id="@+id/imageButton1"
                android:layout_width="0dp"
                android:layout_height="34dp"
                android:layout_gravity="center_vertical"
                android:layout_marginStart="5dp"
                android:layout_weight="1"
                android:background="@null"
                android:contentDescription="@string/Delete_Icon"
                android:tint="@color/Task_Name"
                app:srcCompat="@android:drawable/ic_menu_delete" />

    </LinearLayout>