我在Blackberry中使用ListField
而无法应用row.setChangeListener
。
有人可以帮帮我吗?
这是我的代码,
Friendship objFriendship = new Friendship();
friends = objFriendship.FetchFriends(AATTGlobals.CURRENT_USER.getUserID());
rows = new Vector();
for (int x = 0; x < friends.length; x++) {
String UserName = friends[x].getUserName();
ProfilePicture = MISC.FetchUserProfilePicture(friends[x].getProfilePicturePath());
String Location = friends[x].getLocation();
TableRowManager row = new TableRowManager();
row.add(new BitmapField(ProfilePicture));
LabelField task = new LabelField(UserName,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
};
task.setFont(Font.getDefault().derive(Font.BOLD));
row.add(task);
row.add(new LabelField(Location,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
}
);
row.setChangeListener( new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Row Clicked #");
}
});
没有任何错误消息,但setChangeListener
未触发,此处为TableRowManager
Private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x0099CCFF);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 44, 44);
setPositionChild(field, 10, getRowHeight() / 4);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 70, getRowHeight() / 5);
field = getField(2);
layoutChild(field, field.getPreferredWidth(), fontHeight + 1);
setPositionChild(field, 70, (getRowHeight() / 2) + 5);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
答案 0 :(得分:1)
添加此
//for non touch
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
//for touch
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
尝试这个让我知道它是否有效。
答案 1 :(得分:0)
我注意到,fieldChangeLister / FieldChanged没有被ListField UI调用[因为它适用于按钮和标签。]所以我认为Listfield不支持FieldChanged
在navigationClick / TouchEvent()中,使用FieldChange方法编写您正在编写的操作。