ghs.alshareef
ghs.alshareef

Reputation: 2209

How to create TextView programmatically?

I have created some TextView in the view ml, about 5 of them. But the problem is that after I read from xml file the values come, more than 5 sometimes, and there is no limit. It could be better more than 10. However if I can create the TextView from the activity, then I think I can do it somehow.

Upvotes: 0

Views: 1383

Answers (1)

JOG
JOG

Reputation: 5640

Assuming you want it add to a view called containingView,

TextView myTextView = new TextView(containingView.getContext());
myTextView.setText("alshareef");
containingView.addView(myTextView);

Upvotes: 2

Related Questions