2

私はブラックベリーのアプリケーションで非常に新しいです。

Eclipseを使用してBlackberryで電卓を作成しようとしています:

ボタン(ButtonField)を追加しました。最初のターゲットは、このボタンを押したときに表示したいことです

こんにちは.. テキストフィールドで試してみてください。

ここに私のコードを入れます。

Launcher.java

public class Launcher extends UiApplication {
    public static void main(String[] args) {
        Launcher theApp = new Launcher();
        theApp.enterEventDispatcher();
   }
   private Launcher()
   {
       this.pushScreen(new MainScrn());
   }

}

MainScrn .java

public class MainScrn extends MainScreen implements FieldChangeListener {
    public MainScrn() {
        LabelField lf_hello = new LabelField();
        lf_hello.setText("Hello, World!");
        lf_hello.setBackground(BackgroundFactory.createSolidBackground(124));
        ButtonField mySubmitButton = new ButtonField("clickMe");
        mySubmitButton.setChangeListener(this);
        this.add(lf_hello);
        this.add(mySubmitButton);
    }

    public void fieldChanged(Field field, int context) {
        System.out.println("hi.. now you can try with text field");

    }
}

こんにちは、これで何が問題なのですか。? 助けてください..あなたにとっては非常に簡単ですが、私は今ではありませんか?

4

3 に答える 3

2

フィールド変更リスナーで、このコードを置き換えます

 public void fieldChanged(Field field, int context) {
        System.out.println("hi.. now you can try with text field");
 }

public void fieldChanged(Field field, int context) {
    if(field == mySubmitButton) {
        System.out.println("hi.. now you can try with text field");
    }      
}

やりたいことだけを書かないでください。最初に ButtonField かどうかを確認してから、コードを記述します。

于 2011-11-17T13:40:34.340 に答える
1

これをチェックしてください。

public final class MyScreen extends MainScreen implements FieldChangeListener
{
/**
 * Creates a new MyScreen object
 */

LabelField lbl = new LabelField("hi.. now you can try with text field.");
ButtonField bf = new ButtonField("Click Me",ButtonField.CONSUME_CLICK);
public MyScreen()
{        
    // Set the displayed title of the screen       
    setTitle("MyTitle");
    bf.setChangeListener(this);
    add(bf);

}

public void fieldChanged(Field field, int context) {
    // TODO Auto-generated method stub
    if(field == bf)
    {
        add(lbl);
    }
}
}
于 2011-11-17T09:34:16.303 に答える