blackberry - Update text on a buttonfield when it is clicked -
i'm trying set text on button when clicked. i'm initialising bigvector update text of button value. i'm using counter value determine wihcih bigvector value should selected. problem is, below code expecting counter value final.
a better methodology updating text on field when clicked welcome.
here code -
final bigvector bigstringvectora = new bigvector(); bigstringvectora.addelement("a test answer 1"); bigstringvectora.addelement("a test answer 2"); bigstringvectora.addelement("a test answer 3"); aansweroptionbutton.setchangelistener(new fieldchangelistener() { public void fieldchanged(field field, int context) { aansweroptionbutton.settext((string)bigstringvectora.elementat(counter)); } });
thanks
you can make counter instance variable, either in outer class or in anonymous fieldchangelistener:
aansweroptionbutton.setchangelistener(new fieldchangelistener() { private int counter = 0; public void fieldchanged(field field, int context) { counter++; if (counter > bigstringvectora.size()) { counter = 0; } aansweroptionbutton.settext((string)bigstringvectora.elementat(counter)); } });
Comments
Post a Comment