mergesort
mergesort

Reputation: 5197

How do I add textviews to a screen?

I have an activity that requires a certain number of CheckedTextViews, depending on the length of a JSONArray. What is the best way to do this? Should I use an inflater? Or should I add it programmatically? Which is more efficient? How do I do both?

To make it more clear what I am trying to do:

I have a JSONArray and trying to add three textfields for each element in the jsonarray.

Upvotes: 0

Views: 40

Answers (1)

Nanne
Nanne

Reputation: 64419

Well, I think you should use an inflater and do it programmatically.

Define your view in XML to separate your design/layout and logic. Iterate trough the separate JSON entries, and inflate views while you need them.

The basic step would look something like this:

View inflatedView = View.inflate(this, R.layout.test, null); 
wrapper.addView(inflatedView);

(I put an example online once for a complete how-to. you can check it here)

Upvotes: 1

Related Questions