Hello
I have a loop that creates n-1 textviews, and for each of these textviews I would like a fixed layout defined in an XML file.
The code is as follows:
for(PInfo P : P_array)
{
TextView tv = new TextView(this);
tv.setText(P.getName());
tv.setWidth(P.getLength());
tv.setHeight(70);
tv.setPadding(10, 5, 10, 5);
masterView.addView(tv);
}
I would like something like tv.setLayout(R.id.textviewlayout); … How is that done, im sure its easy (it should be) but I cant find any info on it.
This is called inflating. Try this:
Second parameter is optional parent for inflated view:
help article