Get Button click in each row in Blackberry

2019-06-08 20:32发布

I want to get the button click event in each row. How to get that ?. I tried this link and its working if there is only one button in each row. But in my case, there are more than one button in each row. 10,20 and 11,21 are my buttons.

enter image description here

in RowManager class from the above link, i added the following code -

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


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

Now on StackScreen class, public void fieldChanged(Field field, int context), How i get the name of the clicked buttons ?

标签: blackberry
1条回答
The star\"
2楼-- · 2019-06-08 21:12

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;

and -

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

Then on StackScreen class -

public void fieldChanged(Field field, int context) {
       Object f=field.getCookie();
       Dialog.alert("Button " +f);
 }
查看更多
登录 后发表回答