Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 黑莓点击事件_User Interface_Blackberry - Fatal编程技术网

User interface 黑莓点击事件

User interface 黑莓点击事件,user-interface,blackberry,User Interface,Blackberry,我在VerticalFieldManager中有一个ImageButton,在HorizontalFieldManager中有一个VFM。当我单击周围字段中的任意位置时,ImageButton click事件将触发。我希望单击事件仅在单击ImageButton时触发,而不是字段(VFM或HFM) 代码如下: ImageButton Login=newImageButton(configModel.getLoginButton(),可聚焦| Field.Field_RIGHT,“Login.png

我在VerticalFieldManager中有一个ImageButton,在HorizontalFieldManager中有一个VFM。当我单击周围字段中的任意位置时,ImageButton click事件将触发。我希望单击事件仅在单击ImageButton时触发,而不是字段(VFM或HFM)

代码如下:

ImageButton Login=newImageButton(configModel.getLoginButton(),可聚焦| Field.Field_RIGHT,“Login.png”,“plogin.png”,0x9cbe95);
HorizontalFieldManager hfm=新的HorizontalFieldManager(使用所有宽度);
VerticalFieldManager loginButtonVfm=新的VerticalFieldManager(使用所有宽度);
loginButtonVfm.add(Login);
添加(登录按钮vfm);
添加(hfm);
FieldChangeListener loginListener=新的FieldChangeListener(){
公共无效字段已更改(字段,int上下文){
对话框。警报(“已触发”);
}
}
Login.setChangeListener(loginListener);
ImageButton类代码如下:

公共类ImageButton扩展字段{
//图像按钮类
私有字符串标签;
私人内部标签高度;
专用int_标签宽度;
专用字体(u字体),;
私有位图currentPicture;
私有位图_onPicture;
私人位图(图片);;
内色;
公共图像按钮(字符串文本、长样式、字符串img、字符串img_hvr、int-color){
超级(风格);
_offPicture=Bitmap.getBitmapResource(img);
_onPicture=Bitmap.getBitmapResource(img_hvr);
_font=font.getDefault().derivate(font.BOLD,7,Ui.UNITS\u pt);
_标签=文本;
_labelHeight=_onPicture.getHeight();
_labelWidth=_onPicture.getWidth();
这个颜色=颜色;
_当前图片=_offPicture;
}
公共void setImage(字符串img){
_offPicture=Bitmap.getBitmapResource(img);
_当前图片=_offPicture;
}
/**
*@返回按钮上的文本
*/
公共void setText(字符串文本){
_标签=文本;
}
字符串getText(){
退货标签;
}
/**
*实地执行。
*@请参见net.rim.device.api.ui.Field#getPreferredHeight()
*/
public int getPreferredHeight(){
返回标签高度;
}
/**
*实地执行。
*@请参见net.rim.device.api.ui.Field#getPreferredWidth()
*/
public int getPreferredWidth(){
返回标签宽度;
}
/**
*现场实施。获得焦点后更改图片。
*@see net.rim.device.api.ui.Field#onFocus(int)
*/
受保护的空对焦(整数方向){
_currentPicture=\u onPicture;
//使无效();
超级聚焦(方向);
}
/**
*字段实现。当焦点丢失时更改图片。
*@see net.rim.device.api.ui.Field#onnfocus()
*/
受保护的无效onnfocus(){
_当前图片=_offPicture;
使无效();
super.onnfocus();
}
/**
*实地执行。
*@see net.rim.device.api.ui.Field#drawFocus(图形,布尔值)
*/
//受保护的void drawFocus(图形,布尔打开){
////什么也不做
//      }
受保护的void drawFocus(图形,布尔打开){
如果(打开){
//绘制自己的自定义焦点。
}
}
/**
*实地执行。
*@see net.rim.device.api.ui.Field#布局(int,int)
*/
受保护的空心布局(内部宽度、内部高度){
setExtent(Math.min(width,getPreferredWidth()),
Math.min(height,getPreferredHeight());
}
/**
*实地执行。
*@see net.rim.device.api.ui.Field#paint(图形)
*/
受保护的空心漆(图形){
//首先画背景色和图片
graphics.setColor(this.color);
fillRect(0,0,getWidth(),getHeight());
graphics.drawBitmap(0,0,getWidth(),getHeight(),_currentPicture,0,0);
//然后画文本
图形.设置颜色(颜色.白色);
graphics.setFont(_font);
graphics.setFont(graphics.getFont().derivate(Font.BOLD));
图形.绘图文本(_标签,5,9,
(int)(getStyle()&DrawStyle.省略号| DrawStyle.VALIGN|u掩码| DrawStyle.HALIGN|u掩码),
getWidth()-6);
}
/**
*重写,以便事件分派线程可以捕获此事件
*而不是让它在这里被抓住。。
*@see net.rim.device.api.ui.Field#navigationClick(int,int)
*/
受保护的布尔导航单击(int状态,int时间){
现场更改通知(1);
返回true;
} 
}

当您尝试自己编写自定义字段时,这种情况实际上很容易发现错误。(这不是你的错……BlackBerry Java让这件事变得比实际情况更难!)

我认为解决这个问题最简单的方法是重用别人已经测试过的东西。我建议您查看图书馆,尤其是以下两个课程:

因为我认为他们正是你所需要的。我相信您需要更改或添加到
ImageButton
类中的重要代码如下:

受保护的布尔键字符(字符字符、整型状态、整型时间)
{
if(character==Characters.ENTER){
单击按钮();
返回true;
}
返回super.keyChar(字符、状态、时间);
}
受保护的布尔导航单击(int状态,int时间)
{
如果(状态!=0)单击按钮();
返回true;
}
受保护的布尔跟踪轮单击