专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > BlackBerry

黑莓学习札记之三-对话框和菜单栏

发布时间:2010-05-30 19:38:45 文章来源:www.iduyao.cn 采编人员:星星草
黑莓学习笔记之三--对话框和菜单栏

    菜单项:我们通过在Screen中重写makeMenu()方法来添加菜单。

    protected void makeMenu(Menu menu,int instance)

    在这个方法里,会用到menu.add(MenuItem)来添加一个菜单项。
   
    菜单项这个类就是 MenuItem
   
MenuItem newItem = new MenuItem("Alert", 100, 10){
			public void run(){
				Dialog.inform("Alert Message");
			}
		};


    MenuItem构造子接受下面的3个参数:
    text       菜单项的名称
    ordinal    菜单项的顺序;一个越大的值表明了这个菜单项越靠近菜单的底部。
    priority   接收缺省焦点的菜单项优先级(值越小表示高优先级)
    run()定义了当用户点击菜单项发生的操作的实现。

    对话框: Dialog 继承 PopupScreen 并实现 FieldChangeListener, HolsterListener
    1、Dialog由标题区和用户区组成。用户区包含图标和标题信息;用户区主要由按键组成。
    2、Dialog的排版由DialogManager管理,客户区实际按Vertical居中排列按键,当然也可添加其他Field
    3、Dialog是局部的类,它默认从属于类的某个方法,当Style设置了Dialog. GLOBAL_STATUS后,它就成为全局类,可以在类的任何地方显示执行,包括在构造方法内。
    4、Dialog的Styel除了Screen和Manager外,还有LIST和GLOBAL_STATUS,LIST表示用户区的按键显示形式不是原来的Button形式,而是列表的形式。GLOBAL_STATUS见前。
    5、Dialog有预制、按标准定制和非标准定制三种。

    按标准定制

    系统设置好几个按键的组合形式,包括有
    D_OK,        显示一个字符串,并且提示用户点击OK。
    D_SAVE,      实现一个字符串,并且提示用户点击Save,Discard,或者Cancel;按Escape取消
    D_DELETE,    显示一个字符串,并且提示用户点击Delete或者Cancel;按Escape撤销
    D_YES_NO.    显示一个字符串,并且提示用户点击Yes或No

    这些组合根据按键按下对应返回CANCEL、OK、SAVE、DISCARD、DELETE、YES和NO等值。标准定制时每次type只能选择一个组合。

    Ask除Bitmap已确定为“?”外,其他同Dialog构造函数。

    defaultChoice表示一显示,直接聚焦到第几个按键。

    dontAskAgain – 增加一个’Don’t ask again’ 的检查框。

    Style=0和1(List)两种,其他值未发现有效,即Screen和Manager的style不能影响dialog的样式。

  
 public static int ask(int type)

    public static int ask(int type,String message)

    public static int ask(int type, String message,  int defaultChoice)

    public Dialog(int type, String message, int defaultChoice, Bitmap bitmap, long style)

    public Dialog(int type, String message, int defaultChoice, Bitmap bitmap, long style,boolean dontAskAgain)


    非标准定制

    choices表示要添加到用户区作按键的object,Dialog只是提取他们的string(Object.String)作按键的Label而已,因此对Object添加string就可以了。

    values是对应object的返回值,如果没有,返回值用序号(index)代替。

public static int ask(String message,  Object[] choices, int defaultChoice)

public static int ask(String message, Object[] choices,  int[] values,

int defaultChoice)

 

 public Dialog(String message, Object[] choices,int[] values, int defaultChoice, Bitmap bitmap)

public Dialog(String message, Object[] choices, int[] values, int defaultChoice, Bitmap bitmap, long style)



    一般方法


public int doModal()//执行Dialog,并返回按下的键值。

public void show()//显示Dialog,无返回值。
public void show(int priority)

protected static String[] getResourceChoices(int type)

protected static String getResourceMessage(int type)

protected static int[] getResourceValues(int type)

protected static int getResourceDefaultValue(int type)

protected static int[] getResourceSoftkeyMap(int type)

public void setDialogClosedListener(DialogClosedListener listener)

public RichTextField getLabel()

public int getPreferredWidth()

public int getSelectedValue()

public boolean getDontAskAgainValue()

public final void setDefault(int defaultChoice)

public final void setEscapeEnabled(boolean escapeEnabled)



Dialog 选择项处理方式,如下:
int response = Dialog.ask(Dialog.D_SAVE);

if (Dialog.SAVE == response || Dialog.CANCEL == response)


return
false;

if ( Dialog.DISCARD == response )


_item.deleteItem(_itemIndex);



几个声明的范例:
Dialog myDialog = new Dialog(Dialog.D_SAVE, "My Dialog!", 1,
						Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 1);

				Dialog myDialog2 = new Dialog("Other Dialog", choices, values,
						1, Bitmap.getPredefinedBitmap(Bitmap.QUESTION), 0);

				Dialog.alert("This ia a Alert Dialog!");

				Dialog.ask(Dialog.D_SAVE);

				Dialog.inform("This is a inform Dialog!");








   
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: