我需要用外语创建是/否确认对话框。我想我需要通过扩展Dialog创建自己的类?
由于
答案 0 :(得分: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方法。
E.g
MyDialogScreen dialog = new MyDialogScreen();
UiApplication.getUiApplication().pushModalScreen(dialog);
int result = dialog.getExitState();
干杯
雷