Skip to content Skip to sidebar Skip to footer

Add Textviews Programmatically To A Xml Layout

This is a XML LinearLayout linlayout.xml: Copy

Solution 2:

It would be best to use a ListView. By the way did you change the orientation of your layout to a vertical orientation ? But if it necessary for you i suggesst this : i suppose you have an element with a certain size.

finalintsize=3; // replace with the size of your elementLinearLayoutlinear= (LinearLayout) findViewById(R.layout.mylinear);

for(int i=0;i<size;i++){
    finalTextViewtextView=newTextView(this);
    textView.setText("text "+i);
    textView.setLayoutParams(newLayoutParams(
    LayoutParams.FILL_PARENT,
    LayoutParams.WRAP_CONTENT));

    linear.addView(textView);
}

Post a Comment for "Add Textviews Programmatically To A Xml Layout"