Java 列表字段显示来自URL的图像
我正在显示一个自定义的列表字段,右边是文本,左边是图像。图像动态地来自URL。最初,我在列表字段的左边放置一个空白图像,然后调用URLBITMAPFrEAR类的StURL方法,该方法实际上进行了处理,并将处理后的图像放在空白图像的顶部。但要查看处理后的图像,我需要单击列表字段图像。我希望处理后的图像在处理后自动显示在列表字段中。有人能告诉我哪里出错了吗?我一直在寻求帮助,但似乎没有人能解决问题。任何有建设性的建议都将不胜感激Java 列表字段显示来自URL的图像,java,blackberry,Java,Blackberry,我正在显示一个自定义的列表字段,右边是文本,左边是图像。图像动态地来自URL。最初,我在列表字段的左边放置一个空白图像,然后调用URLBITMAPFrEAR类的StURL方法,该方法实际上进行了处理,并将处理后的图像放在空白图像的顶部。但要查看处理后的图像,我需要单击列表字段图像。我希望处理后的图像在处理后自动显示在列表字段中。有人能告诉我哪里出错了吗?我一直在寻求帮助,但似乎没有人能解决问题。任何有建设性的建议都将不胜感激 import java.util.Vector; import net
import java.util.Vector;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.ContextMenu;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.container.FullScreen;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.util.Arrays;
import net.rim.device.api.ui.component.ListField;
public class TaskListField extends UiApplication {
// statics
// ------------------------------------------------------------------
public static void main(String[] args) {
TaskListField theApp = new TaskListField();
theApp.enterEventDispatcher();
}
public TaskListField() {
pushScreen(new TaskList());
}
}
class TaskList extends MainScreen implements ListFieldCallback {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
private Bitmap p3;
String Task;
ListField listnew = new ListField();
private VerticalFieldManager metadataVFM;
TableRowManager row;
public TaskList() {
super();
URLBitmapField artistImgField;
listnew.setRowHeight(80);
listnew.setCallback(this);
rows = new Vector();
for (int x = 0; x <3; x++) {
row = new TableRowManager();
artistImgField = new URLBitmapField(Bitmap
.getBitmapResource("res/images/bg.jpg"));
row.add(artistImgField);
String photoURL = "someimagefrmurl.jpg";
Log.info(photoURL);
// strip white spaces in the url, which is causing the
// images to not display properly
for (int i = 0; i < photoURL.length(); i++) {
if (photoURL.charAt(i) == ' ') {
photoURL = photoURL.substring(0, i) + "%20"
+ photoURL.substring(i + 1, photoURL.length());
}
}
Log.info("Processed URL: " + photoURL);
artistImgField.setURL(photoURL);
LabelField task = new LabelField("Display");
row.add(task);
LabelField task1 = new LabelField(
"Now Playing" + String.valueOf(x));
Font myFont = Font.getDefault().derive(Font.PLAIN, 12);
task1.setFont(myFont);
row.add(task1);
rows.addElement(row);
}
listnew.setSize(rows.size());
this.add(listnew);
//listnew.invalidate();
}
// ListFieldCallback Implementation
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width) {
TableRowManager rowManager = (TableRowManager) rows.elementAt(index);
rowManager.drawRow(g, 0, y, width, listnew.getRowHeight());
}
protected void drawFocus(Graphics graphics, boolean on) {
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
// Causes the fields within this row manager to be layed out then
// painted.
public void drawRow(Graphics g, int x, int y, int width, int height) {
// Arrange the cell fields within this row manager.
layout(width, height);
// Place this row manager within its enclosing list.
setPosition(x, y);
// Apply a translating/clipping transformation to the graphics
// context so that this row paints in the right area.
g.pushRegion(getExtent());
// Paint this manager's controlled fields.
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
// Restore the graphics context.
g.popContext();
}
// Arrages this manager's controlled fields from left to right within
// the enclosing table's columns.
protected void sublayout(int width, int height) {
// set the size and position of each field.
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
// start with the Bitmap Field of the priority icon
Field field = getField(0);
layoutChild(field, 146,80);
setPositionChild(field, 0, 0);
// set the task name label field
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 149, 3);
// set the list name label field
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 149, fontHeight + 6);
setExtent(360, 480);
}
// The preferred width of a row is defined by the list renderer.
public int getPreferredWidth() {
return listnew.getWidth();
}
// The preferred height of a row is the "row height" as defined in the
// enclosing list.
public int getPreferredHeight() {
return listnew.getRowHeight();
}
}
public Object get(ListField listField, int index) {
// TODO Auto-generated method stub
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
// TODO Auto-generated method stub
return 0;
}
}
import java.util.Vector;
导入net.rim.device.api.system.Bitmap;
导入net.rim.device.api.system.Display;
导入net.rim.device.api.ui.ContextMenu;
导入net.rim.device.api.ui.DrawStyle;
导入net.rim.device.api.ui.Field;
导入net.rim.device.api.ui.Font;
导入net.rim.device.api.ui.Graphics;
导入net.rim.device.api.ui.Manager;
导入net.rim.device.api.ui.MenuItem;
导入net.rim.device.api.ui.ui应用程序;
导入net.rim.device.api.ui.component.BitmapField;
导入net.rim.device.api.ui.component.Dialog;
导入net.rim.device.api.ui.component.LabelField;
导入net.rim.device.api.ui.component.ListField;
导入net.rim.device.api.ui.component.ListFieldCallback;
导入net.rim.device.api.ui.component.NullField;
导入net.rim.device.api.ui.container.FullScreen;
导入net.rim.device.api.ui.container.main屏幕;
导入net.rim.device.api.ui.container.VerticalFieldManager;
导入net.rim.device.api.util.array;
导入net.rim.device.api.ui.component.ListField;
公共类TaskListField扩展了UiApplication{
//静力学
// ------------------------------------------------------------------
公共静态void main(字符串[]args){
TaskListField theApp=新建TaskListField();
theApp.enterEventDispatcher();
}
公共任务列表字段(){
推屏(新任务列表());
}
}
类TaskList扩展MainScreen实现ListFieldCallback{
专用向量行;
私有位图p1;
私有位图p2;
私有位图p3;
字符串任务;
ListField listnew=新ListField();
私有VerticalFieldManager元数据vfm;
TableRowManager行;
公共任务列表(){
超级();
URLBitmapField ArtistingField;
listnew.setRowHeight(80);
setCallback(this);
行=新向量();
对于(int x=0;x,最后我自己解决了它。这很有效:
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
listnew.invalidate();
}
},500,true);
这是因为焦点未聚焦的问题吗?问题是,处理后的图像在列表字段空白图像中很好地被替换,但要查看该图像,我需要单击特定的列表字段项。我希望它能够自动显示图像,而不会被聚焦或未聚焦