Пример приложения BlackBerry ButtonField
Я очень новичок в применении черных ягод.
сейчас пытаюсь создать калькулятор в black berry с помощью eclipse:
поэтому я добавил кнопку (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");
}
}
привет что не так в этом.? Пожалуйста, помогите.. это будет довольно просто для вас, но я не сейчас?
3 ответа
Решение
Проверь это.
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);
}
}
}
Попробуй это:
buttons.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
System.out.println("hi.. now you can try with text field");
Dialog.alert("hi.. now you can try with text field");
}
});
В слушателе с измененным полем замените этот код
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, затем напишите код для него.