获取按钮单击黑莓每一行 [英] Get Button click in each row in Blackberry

查看:116
本文介绍了获取按钮单击黑莓每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要得到每行中的按钮单击事件。如何获取?我想这<一个href=\"http://stackoverflow.com/questions/13664810/how-to-make-a-screen-like-this-on-blackberry/13669417\">link和其工作,如果仅存在一个每一行中按钮。但在我的情况下,有各行的多个按钮。 10,20和11,21是我的按钮。

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.

从上面的链接RowManager类,添加以下code -

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

现在的StackScreen类,公共无效fieldChanged(场场,诠释上下文),我如何获得点击按钮的名称?

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

推荐答案

解决了我的自我 -

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

这篇关于获取按钮单击黑莓每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆