John John - 1 month ago 7
Android Question

I wanna build something as in Image but couldnot start

I am new to android. I wanna do something as in picture. I have a form where the user enters the data. The data entered should be placed in the A and B of 1. If they enter only data in only one form i want to display
only one layout indicated as '1'. When user enter data in 3 forms, i want to display 3 layout indicated as 1, 2 and 3. In the same way when they enter data in 100 forms, i want to display 100 such. How can i achieve this??? Since I am new please explain me full logical part.Here is my image

Answer

You can add views dynamically to your layout. LinearLayout is appropriate parent viewgroup for this type. Create a single layout containing single 'A' and 'B' views.

for(int i=0; i<100; i++) {
    View view = LayoutInflater.from(context).inflate(R.layout.yourSingleView, null);
    TextVeiw a = (TextView) view.findViewById(R.id.text_view_a);
    TextView b = (TextView) view.findViewById(R.id.text_view_b);
    a.setText(formInput[i][0]);
    b.setText(formInput[i][1]);
    parentView.add(view);
}

Other ways can be using a listview or recyclerview. Depends upon your need. BTW i don't see any reason to take 100 inputs from user like this.

Comments