Lokendra
Lokendra

Reputation: 79

How to dynamically increase TableRows

I basically need to put the idea in my game i.e. Cows and Bulls. The screenshot of my main screen is as shown below:

enter image description here

Now, what I want to do is that when I click on the submit button, after entering a valid number, the result of the number of cows and bulls (for example "2 cows 0 bulls") should be shown inside a new row in the table which will be placed just below the Submit button.

Now whenever I click the submit button next after entering another valid number automatically a new row should be created in the same table. this row should hold the current result of the cow and bulls and so on. Example:

enter image description here

Upvotes: 0

Views: 135

Answers (1)

Shobhit
Shobhit

Reputation: 647

Why don't you use a ListView? Here is the official documentation and here is a good article about it. ListView would be a better option as it would fit in nicely with the look and feel of Android. The contacts application, message application, all use ListView.

If you still want to use TableLayout, check this tutorial here. You would basically need to first create a View class' object, populate it with whatever information you need to provide to it and then add that object to table row object using

newTableRowObject.addView(column1ViewObject);
newTableRowObject.addView(column2ViewObject);
...

and then finally add this object to table layout

tableLayoutObject.addView(newTableRowObject);

Upvotes: 1

Related Questions