add dynamic view in android from xml

Solutions on MaxInterview for add dynamic view in android from xml by the best coders in the world

showing results for - "add dynamic view in android from xml"
Matteo
20 Jul 2017
1// Parent layout
2LinearLayout parentLayout = (LinearLayout)findViewById(R.id.layout);
3
4// Layout inflater
5LayoutInflater layoutInflater = getLayoutInflater();
6View view;
7
8for (int i = 1; i < 101; i++){
9    // Add the text layout to the parent layout
10    view = layoutInflater.inflate(R.layout.text_layout, parentLayout, false);
11
12    // In order to get the view we have to use the new view with text_layout in it
13    TextView textView = (TextView)view.findViewById(R.id.text);
14    textView.setText("Row " + i);
15
16    // Add the text view to the parent layout
17    parentLayout.addView(textView);
18}
19