2013-03-22 76 views
1

我想要获取每行中的按钮单击事件。如何得到那个?我试过这个link和它的工作,如果每行只有一个按钮。但就我而言,每行都有不止一个按钮。 10,20和11,21是我的按钮。获取按钮单击黑莓中的每一行

enter image description here

从上面的链接RowManager类

,添加以下代码 -

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

现在上StackScreen类,公共无效fieldChanged(场场,INT上下文),我怎么得到点击按钮的名称?

+1

下面一个是好的。 – alishaik786 2013-03-22 17:35:33

回答

2

解决了我的自我 -

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类 -

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