Ok, im hoping this will be quite an easy thing for somebody to answer..
This works :-
All I am doing is building up the tablelayout with my rows... this add's two progress bars to my layout.
When I introduce a loop... it only works on the first item, then crashes
I don't understand why it crashes using the loop idea? I have a feeling whats happening is I call this method the first time, and it works as its the first time (item 0) is used, but the second time I call it the loop has to do item 0 and 1, so it crashes trying to add the 1st one again (because maybe I need to unload it first?)
Everytime I click a button on the form, 'ItemCount' is incremented by 1, and this method is called, so it adds one progress bar everytime the button is clicked. The progressbar etc are declared before this method is called.
It's a little hard to explain, but any ideas are welsome
This works :-
Code:
public void updateDisplay() {
item=0;
myTableLayout.removeAllViews();
TableRows[item].addView(ProgressBars[item]);
myTableLayout.addView(TableRows[item]);
item++;
TableRows[item].addView(ProgressBars[item]);
myTableLayout.addView(TableRows[item]);
When I introduce a loop... it only works on the first item, then crashes
Code:
public void updateDisplay() {
TableLayout myTableLayout = new TableLayout(this);
myTableLayout.removeAllViews();
for (item=0;item<ItemCount;item++ ) {
TableRows[item].removeAllViews();
TableRows[item].addView(ProgressBars[item]);
myTableLayout.addView(TableRows[item]);
}
Everytime I click a button on the form, 'ItemCount' is incremented by 1, and this method is called, so it adds one progress bar everytime the button is clicked. The progressbar etc are declared before this method is called.
It's a little hard to explain, but any ideas are welsome