Get Button click in each row in Blackberry

两盒软妹~` 提交于 2019-12-08 05:01:10

问题


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.

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 ?


回答1:


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);
 }


来源:https://stackoverflow.com/questions/15565693/get-button-click-in-each-row-in-blackberry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!