0

my app needs an add button that adds two Edittext and another button every time they click the add button adds again the same three things under the added ones, I attached a screenshot of how my app suppose to work, I really need help in this I am new in android development.

here is my activity layout

<?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:layout_height="match_parent"
    tools:context=".Mark_calc">

    <include
        android:id="@+id/Mark_calcTB"
        layout="@layout/toolbar"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/add_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="12dp"
        android:layout_marginBottom="12dp"
        android:clickable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:srcCompat="@drawable/ic_add" />

    <TextView
        android:id="@+id/Box_1"
        android:layout_width="0dp"
        android:layout_height="207dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="12dp"
        android:layout_marginEnd="10dp"
        android:background="@drawable/rounded_button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/Mark_calcTB" />

    <TextView
        android:id="@+id/Total_MarksTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="40dp"
        android:layout_marginTop="40dp"
        android:text="Total marks:"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/Box_1" />

    <TextView
        android:id="@+id/result_total_marksTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="52dp"
        android:layout_marginEnd="85dp"
        android:text="0"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/Mark_calcTB" />

    <TextView
        android:id="@+id/total_hours"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="44dp"
        android:layout_marginBottom="40dp"
        android:text="Total hours:"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="@+id/Box_1"
        app:layout_constraintStart_toStartOf="parent" />

    <TextView
        android:id="@+id/result_total_hours"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="84dp"
        android:layout_marginBottom="40dp"
        android:text="0"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="@+id/Box_1"
        app:layout_constraintEnd_toEndOf="parent" />

    <EditText
        android:id="@+id/mark1"
        android:layout_width="144dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginTop="28dp"
        android:ems="10"
        android:hint="Mark%"
        android:inputType="numberSigned"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/Box_1" />

    <EditText
        android:id="@+id/hours1"
        android:layout_width="144dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="24dp"
        android:layout_marginTop="28dp"
        android:ems="10"
        android:hint="Hours"
        android:inputType="numberSigned"
        app:layout_constraintStart_toEndOf="@+id/mark1"
        app:layout_constraintTop_toBottomOf="@+id/Box_1" />

    <Button
        android:id="@+id/delete_button"
        android:layout_width="35dp"
        android:layout_height="38dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="32dp"
        android:background="@drawable/ic_delete"
        app:layout_constraintStart_toEndOf="@+id/hours1"
        app:layout_constraintTop_toBottomOf="@+id/Box_1" />


</androidx.constraintlayout.widget.ConstraintLayout>

and here is a screenshot of how it should work.

3
  • use recyclerview instead and on pressing add button increase the count and start notifydatasetchange. Commented Feb 2, 2020 at 20:04
  • Can you please show me how I am new in android development @HaiderSaleem Commented Feb 2, 2020 at 20:08
  • take a look at stackoverflow.com/questions/44719750/… Commented Feb 2, 2020 at 20:16

1 Answer 1

1

Take Recyclerview and when you click on add Button add the data to your ArrayList and update the adapter to NotifyDataSetChanges.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.