我正在开发Blackberry OS4.5,我有一个关于“改变焦点时刷新屏幕”的问题
private void drawImageScrollView(Vector vImages) {
// Horizontal Field
HorizontalFieldManager imgScrollView = new HorizontalFieldManager(
USE_ALL_WIDTH | HORIZONTAL_SCROLL);
SimpleItemData itemData = new SimpleItemData();
// Get list bitmap
for (int i = 0; i < vImages.size(); i++) {
itemData = (SimpleItemData) vImages.elementAt(i);
BitmapField bmf = new BitmapField(itemData.getImage(), BitmapField.ACTION_INVOKE | BitmapField.FOCUSABLE) {
protected void drawFocus(Graphics graphics, boolean on) {
graphics.setColor(Color.BLUE);
graphics.drawRect(0, 0, getWidth() - 4, getHeight() - 4);
graphics.drawRect(1, 1, getWidth() - 6, getHeight() - 6);
}
// When focus on image display new information
protected void onFocus(int direction) {
// Change focus and add processing here
super.onFocus(direction);
}
};
bmf.setPadding(2, 2, 2, 2);
bmf.setMargin(2, 2, 2, 2);
imgScrollView.add(bmf);
}
add(imgScrollView);
}
如上面的源代码,你可以看到“onFocus”方法。我想在这里获取新数据和刷新屏幕,但我不知道哪种方法可以刷新当前屏幕?我尝试了一些方法,例如:doPaint(),invalidate(),...但不工作@@ 我没有解决这个问题的方法。如果可以,请帮助我......
非常感谢你!
答案 0 :(得分:0)
为此目的,最好使用FocusChangeListner观察以下示例,它将帮助您刷新字段并重新加载指定的字段(在我的情况下,我拿了一个标签)
例如,当我将图像聚焦到我的Imagescroll上时,它应显示其编号。
注意:为了测试这个例子,请从这里下载图像http://developer.android.com/resources/tutorials/views/hello-gridview.html它很容易测试,你必须根据你的项目更改图像
public class StartUp extends UiApplication
{
public static void main(String[] args) {
StartUp start=new StartUp();
start.enterEventDispatcher();
}
public StartUp()
{
UiApplication.getUiApplication().pushScreen(new RefreshSCreen());
}
}
class RefreshSCreen extends MainScreen implements FocusChangeListener
{
HorizontalFieldManager imgScrollView;
VerticalFieldManager vmanager;
LabelField lable;
BitmapField bmf[];
private Vector vImages=null;
public RefreshSCreen() {
vImages=new Vector();
for(int i=0;i<8;i++){
Bitmap image=Bitmap.getBitmapResource("sample_"+i+".jpg");
vImages.addElement(image);
}
imgScrollView = new HorizontalFieldManager(
USE_ALL_WIDTH | HORIZONTAL_SCROLL);
// Get list bitmap
bmf=new BitmapField[vImages.size()];
for (int i = 0; i < vImages.size(); i++) {
bmf[i] = new BitmapField((Bitmap) vImages.elementAt(i), BitmapField.ACTION_INVOKE | BitmapField.FOCUSABLE) {
protected void drawFocus(Graphics graphics, boolean on) {
graphics.setColor(Color.BLUE);
graphics.drawRect(0, 0, getWidth() - 4, getHeight() - 4);
graphics.drawRect(1, 1, getWidth() - 6, getHeight() - 6);
}
};
bmf[i].setFocusListener(this);
bmf[i].setPadding(2, 2, 2, 2);
bmf[i].setMargin(2, 2, 2, 2);
imgScrollView.add(bmf[i]);
}
add(imgScrollView);
vmanager=new VerticalFieldManager();
add(vmanager);
}
public void focusChanged(Field field, int eventType) {
for(int i=0;i<vImages.size();i++){
if(field==bmf[i]){
if(bmf[i].isFocus()){
synchronized (UiApplication.getEventLock()) {
vmanager.deleteAll();
vmanager.invalidate();
lable=new LabelField("Hi I am reference of Image number "+i);
vmanager.add(lable);
}
}
}
}
}
}