Skip to content

Instantly share code, notes, and snippets.

@maxmumford
Last active June 2, 2021 16:47
Show Gist options
  • Save maxmumford/7695646 to your computer and use it in GitHub Desktop.
Save maxmumford/7695646 to your computer and use it in GitHub Desktop.
String[] info = new String[2];
info[0] = "info 1";
info[1] = "info 2";
LayoutInflater layoutInflator = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout insertPoint = (LinearLayout) findViewById(R.id.linearLayout1);
List views = new ArrayList();
for(int i=0; i < info.length; i++){
View view = layoutInflator.inflate(R.layout.linearLayout1, null);
TextView textView = (TextView) view.findViewById(R.id.textView1);
textView.setText(info[i]);
views.add(view);
}
for(int i = 0; i < views.size(); i++)
insertPoint.addView(views.get(i));
@m4theuslim4
Copy link

How to obtain a specific view if you add views in loop? i have the same code in my project but cant return a specific view value on click button inside this view

@Sarthak77tiwari
Copy link

Sarthak77tiwari commented Jun 2, 2021

insertPoint.addView(views.get(i)); getting error is Required type:View
Provided:Object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment