1

I want to display 26 textviews. How to display an array of TextViews in android dynamically?

2 Answers 2

2

Create an xml layout which consist of a scrollview containing a linearlayout with orientation vertical.

In the activity, get the linear layout by using findViewById function.

Run a for loop to create a textview with relevant text and continue calling

addView method on this LinearLayout.

Sign up to request clarification or add additional context in comments.

Comments

1

see the bellow code

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    LinearLayout ll=new LinearLayout(this);
    for(int i=0;i<26;i++){
        TextView tv=new TextView(this);
        // or get your TextView from array
        char c=(char)(65+i);
        tv.setText(" "+c);
        ll.addView(tv);
    }
    setContentView(ll);
 }

but this type of design is not good,instead try to use ListView with CustomAdapters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.