且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取按钮单击黑莓每一行

更新时间:2023-02-05 10:43:10

解决了我的自我 -

Solved By My self -

public static int v=0;
button = new ButtonField("1" + index, ButtonField.CONSUME_CLICK);
button.setCookie(new Integer(v+1));  //set cookie
button.setFont(textFont);
add(button);
v=v+1; //increment the value of v

button1 = new ButtonField("2" + index, ButtonField.CONSUME_CLICK);
button1.setCookie(new Integer(v+1));
button1.setFont(textFont);
add(button1);
v=v+1;

和 -

 public void setChangeListener(FieldChangeListener listener) {
     // only the button field supports change listeners
     button.setChangeListener(listener);
     button1.setChangeListener(listener);
  }

然后在StackScreen类 -

Then on StackScreen class -

public void fieldChanged(Field field, int context) {
       Object f=field.getCookie();
       Dialog.alert("Button " +f);
 }