-1

A week ago I started my todo-list app project and I am learning a lot. I'd like to know about a specific case I couldn't find.

The case: I try to create a "layout-item" of type Linearlayout as a task with specific views inside of it like "Task name, Task description, time, delete button" inside another Linearlayout. But here is the thing, the views of the first Linearlayout are all having a specific position inside of it. I want to keep the positions of the views. How do I create this kind of Layout as an item?

Another short question: When I create this Layout how do I delete it programmatically?

Here you can find my created design and how exactly the "layout-item" (tasks) should look like App design preview

    <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>
Caconde
  • 4,177
  • 7
  • 35
  • 32

2 Answers2

1

Ahmed is correct, you would use a recycler and create a view that had: Task name, Task description, time, delete button. You then can remove and add items by editing the array that contains your items.

Here is a simple recycler example: Simple Android RecyclerView example

Kory
  • 31
  • 4
0

You can use a RecyclerView as described here:

https://developer.android.com/guide/topics/ui/layout/recyclerview

Ahmed AlAskalany
  • 1,600
  • 1
  • 13
  • 13
  • 1
    I read the documentation and I figured out how to use the recyclerview. Thank you very much, Ahmed. I would like to know just one thing (maybe I find it out by myself): How do I implement a date textview inside of the recyclerview and sort all tasks by their given date value? I'd like to create the new date textviews dynamically as example when I create a new task with a date that isn't in the tasks list. – MonsieurFriend Aug 30 '19 at 22:54
  • Check this answer which shows how to use an implementation of a Comparator and use it to sort the items list in the RecyclerView's adapter: https://stackoverflow.com/a/48090364/6798074 This one also: https://stackoverflow.com/a/50564091/6798074 Remember to call the data change notification methods on the adapter whenever the date for one or more tasks has changed, so that the recycler view applies these changes to the UI. – Ahmed AlAskalany Aug 31 '19 at 17:13