androidrootview

Android - Getting Objects in Multiple RootView


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


Solution

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

    RecyclerView Tutorial @ Developer.Android