问题
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