如何创建自定义对话框 [英] How to create a custom dialog

查看:194
本文介绍了如何创建自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to create yes/no confirmation dialog in a foreign language. I think I need to create my own class by extending Dialog ?

感谢

推荐答案

这应该做的伎俩。我道歉对任何瑞典厨师观望。

this should do the trick. My apologies to any Swedish chefs watching.

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

正如你可以看到上面有可能只是通过这种方法,所以你不应该需要一个定制类的另一种语言来创建一个对话框来改变所有文字(语言),在对话框的值。

As you can see from the above it is possible to change all the text (language) values on a Dialog just by using this method so you shouldn't need a custom class to create a Dialog in another language.

如果您使用标准的BB本地化接近简单的方法这是更简单(Dialog.ask(res.getString(SOMEQUESTION))将自动有它的afirmative和调整,在手机选项中设置语言负的按钮。你才会需要补充的问题作为一个字符串资源。

It's even simpler if you use the standard BB localizing approach the simpler method (Dialog.ask(res.getString(SOMEQUESTION)) will automatically have it's afirmative and negative buttons adjusted for the language set in the phones options. You will only need to add the question as a string resource.

您可以找到这里有效的方法和构造函数列表:
<一href=\"http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/component/Dialog.html\" rel=\"nofollow\">http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/component/Dialog.html

You can find a list of valid methods and constructors here: http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/component/Dialog.html

以下多个编辑:

我认为我上面的答案是你所追求的,但如果你确实需要进一步自定义对话框中一个新的类可能会做这样的:

I thought my above answer was what you were after but if you do need to further customize the dialog in a new class you may do it like this:

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的previous屏幕上方框的对话框。

In the above I've created a new screen and I have overridden the sublayout method to specify a custom width, height and xy positions in layoutDelegate. When you push this screen you will see it as a dialog like box above the previous screen on the stack at the XY positions you specified.

请务必使用pushModal。这将允许你在屏幕上已经从显示栈中弹出后访问getExitState方法。

Make sure to use pushModal. This will allow you to access the getExitState method after the screen has been popped from the display stack.

例如

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

干杯

这篇关于如何创建自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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