0
public class OccuMechanical extends android.support.v4.app.Fragment {

    private View v_schedule;
    private LinearLayout layout_schedule;
    private ImageButton iv_add_schedule;

    private int i = 0;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View v = inflater.inflate(R.layout.fragment_occu_mechanical, container, false);

        layout_schedule = (LinearLayout) v.findViewById(R.id.layout_mech_schedule);

        iv_add_schedule = (ImageButton) v.findViewById(R.id.iv_add_schedule);
        iv_add_schedule.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                i++;
                v_schedule = LayoutInflater.from(getActivity()).inflate(R.layout.layout_mech_schedule, null);
                layout_schedule.addView(v_schedule);
                EditText et = (EditText) layout_schedule.getRootView().findViewById(R.id.layout_description);
                et.setText("Test: " + String.valueOf(i));
            }
        });
        return v;
    }
}

idk if my term is right in the title but here's what im doing... when I click the 'Add more equipment' it adds layout to my app so I want to get all the EditText inside the layout i added in the RootView, I tried setting the text to test it but the first editText of the first rootView is the only one updating. All the codes in my fragment listed above. attached image is the result of this code.

image result

Eco L. Ken
  • 13
  • 7
  • btw , the first row is default in the layout. the 2nd row is the first layout that shows after clicking the 'Add more equipment' button – Eco L. Ken Sep 04 '18 at 01:57
  • I would like to suggest you to use RecyclerView for this task. Each row is a item of the item list. Whenever user click on add more equipment, you add a new item into the item list and then update the adapter with notifydatachanged() or similar function. – hjchin Sep 04 '18 at 02:33
  • you can find more information of RecyclerView on https://developer.android.com/guide/topics/ui/layout/recyclerview – hjchin Sep 04 '18 at 02:35
  • @hjchin Thanks for this suggestion and reminding me about the RecyclerView, I'll try it out later – Eco L. Ken Sep 04 '18 at 02:52

1 Answers1

0

I've done this task by using *RecyclerView as @hjchin suggested. Thank You!

RecyclerView Tutorial @ Developer.Android

Eco L. Ken
  • 13
  • 7