How to get values from dynamic editText views

GabbyCruiseGabbyCruise Member
edited August 23 in General

I have created a LinearLayout with 4 Inputs of string and double data type with two buttons(Add More, and Proceed).

When i click on the AddMore Button, and another set of input fields is added below the first one according to how many times it is clicked,(I'VE DONE THIS)

When i click on the Proceed button, * I want to get values supplied on the dynamic fields according to the number of times the views are added below. and i want to make calculations together with the first 4 fields and then pass these values to the next activity for further processing

The dynamic fields

<EditText
    android:id="@+id/product_name_main"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"
    android:hint="Product Name"
    android:inputType="text"
    android:paddingStart="20dp"
    android:paddingLeft="20dp"
    android:paddingTop="10dp"
    android:paddingEnd="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:textSize="14sp" />

<EditText
    android:id="@+id/product_number_main"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"

    android:ems="10"
    android:hint="Product Number"
    android:inputType="number"
    android:paddingStart="20dp"
    android:paddingLeft="20dp"
    android:paddingTop="10dp"
    android:paddingEnd="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:textSize="14sp" />

<EditText
    android:id="@+id/product_price_main"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"

    android:ems="10"
    android:hint="Product Price"
    android:inputType="number"
    android:paddingStart="20dp"
    android:paddingLeft="20dp"
    android:paddingTop="10dp"
    android:paddingEnd="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:textSize="14sp" />

<EditText
    android:id="@+id/product_quantity_main"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="16dp"
    android:layout_marginRight="16dp"

    android:ems="10"
    android:hint="Product Quantity"
    android:inputType="number"
    android:paddingStart="20dp"
    android:paddingLeft="20dp"
    android:paddingTop="10dp"
    android:paddingEnd="10dp"
    android:paddingRight="10dp"
    android:paddingBottom="10dp"
    android:textSize="14sp" />

The Add More button


public void onAddField(View view) { LayoutInflater inflater = (LayoutInflater); getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View rowView = inflater.inflate(R.layout.field, null); //adding the new row before the add field button. parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1); }
Sign In or Register to comment.