gpt4 book ai didi

java - BlackBerry BitmapField 关于焦点更改和单击监听器

转载 作者:行者123 更新时间:2023-12-01 16:00:54 24 4
gpt4 key购买 nike

我想更改 BitmapField 图像的 onFocus 和 onUnfocus,并且我需要一个 onClick 事件。我怎样才能做到这一点?这是我的代码,但它在焦点更改时触发事件。

public class ClickbleImage extends BitmapField {
public ClickbleImage(Bitmap bitmap,long style) {
super(bitmap,style);
}

public boolean isFocusable() {
return true;
}

protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}

protected void onFocus(int direction) {
this.setBitmap(Bitmap.getBitmapResource("img/editfocus.jpg"));
super.onFocus(direction);
}

protected void onUnfocus() {
this.setBitmap(Bitmap.getBitmapResource("img/edit.png"));
super.onUnfocus();
}
}

最佳答案

我不完全确定“它在焦点变化时触发事件”是什么意思。这不是你想要的吗?

上个月我开发了一个自定义位图按钮,最终创建了 Field 的子类,并自己处理绘图。我不记得为什么 BitmapField 的子类不起作用,但您可能想看看。你会有更多的控制权。

此外,您需要在 onFocusonUnFocus 方法中添加对 invalidate() 的调用,因为这会导致字段用新的位图重新绘制。最后,考虑重写 drawFocus() 并在该方法内不执行任何操作,因为这将阻止绘制标准焦点样式(蓝色光环)。除非您愿意,但如果您有自己的焦点图像,这可能是不可取的。

如果您发布有关该问题的更多详细信息,我可以尝试提供帮助,但我不确定问题是什么。

编辑添加:

我查看了我的笔记,发现了这个链接,

http://www.thinkingblackberry.com/archives/167

再看一下,BB JDE 5.0 的samples\com\rim\samples\device\目录下有一个custombuttonsdemo。它基本上完全实现了该博客文章所描述的内容,这可能会有所帮助。该博客文章描述了绘制自定义按钮,而不是使用位图,但这是相同的想法。在 paint(Graphics g) 方法中,您将执行

protected void paint(Graphics g) {
g.drawBitmap(0,0,getWidth(),getHeight(),bmp,0,0);
}

RIM 示例包含一个实现位图按钮的PictureBackgroundButtonField。这是我使用的,比我上面写的更详细。

关于java - BlackBerry BitmapField 关于焦点更改和单击监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3957371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com