1

我需要用外语创建是/否确认对话框。我想我需要通过扩展 Dialog 创建自己的类?

谢谢

4

1 回答 1

5

这应该可以解决问题。我向所有观看的瑞典厨师道歉。

int answer = Dialog.ask("Gersh gurndy morn-dee burn-dee, burn-dee, flip-flip-flip-flip-flip-flip-flip-flip-flip?", new String[] {"Hokey dokey","Bork bork bork"}, new int[] {Dialog.OK,Dialog.CANCEL}, Dialog.CANCEL);

编辑:

The above explained better: 
public final static int NEGATIVE = 0;
public final static int AFIRMATIVE = 1;
public final static int DEFAULT = NEGATIVE;
int answer = Dialog.ask("question?", new String[] {"afirmative button label", "negative button label"}, new int[] {AFIRMATIVE,NEGATIVE}, DEFAULT);

从上面可以看出,只需使用此方法即可更改 Dialog 上的所有文本(语言)值,因此您不需要自定义类来创建另一种语言的 Dialog。

如果您使用标准 BB 本地化方法,则更简单,更简单的方法 (Dialog.ask(res.getString(SOMEQUESTION)) 将自动根据手机选项中设置的语言调整它的肯定和否定按钮。您只需要添加问题作为字符串资源。

您可以在此处找到有效方法和构造函数的列表:http: //www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/component/Dialog.html

更多编辑如下:

我认为我的上述答案是您所追求的,但如果您确实需要在新课程中进一步自定义对话框,您可以这样做:

public class MyDialogScreen extends MainScreen implements LocalResource {

    private int exitState;

    ...

    protected void sublayout( int width, int height ) {
        setExtent( dialogWidth, dialogHeight );
        setPosition( XPOS, YPOS );
        layoutDelegate( dialogWidth, dialogHeight );
    }

    // do some stuff and assign exitState appropriately
    // e.g. a button that sets exitState = 1 then pops this screen
    // another button that sets exitState = 2 then pops this screen
    ...  

    public int getExitState() 
    {
        return this.exitState;
    }

在上面,我创建了一个新屏幕,并重写了 sublayout 方法以在 layoutDelegate 中指定自定义宽度、高度和 xy 位置。当您按下此屏幕时,您将在您指定的 XY 位置处将其视为堆栈上前一个屏幕上方的对话框。

确保使用 pushModal。这将允许您在屏幕从显示堆栈中弹出后访问 getExitState 方法。

例如

MyDialogScreen dialog = new MyDialogScreen();
UiApplication.getUiApplication().pushModalScreen(dialog);
int result = dialog.getExitState();

干杯

射线

于 2011-03-08T13:13:39.510 回答