2011-11-24 55 views
1

我在黑莓中使用ListField,無法應用row.setChangeListener。 任何人都可以幫我嗎? 這裏是我的代碼,BlackBerry - 如何將clickEvent(setChangeListener)添加到BlackBerry中的ListField?

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

是否有錯誤訊息?什麼是TableRowManager? –

+0

什麼是TableRowManager()在你的application.let中我知道代碼然後只有任何人都可以幫助你。所以請附上您的TableRowManager()代碼。 –

+0

你確定使用'ListField'嗎?您提供的代碼中沒有'ListField'實例。 –

回答

1

在tableRowManager添加此

//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); 
       } 

試試這個讓我知道它工作與否。

+0

它不工作的朋友。 我們有其他代碼寫在別的地方嗎? –

0

我注意到,fieldChangeLister/FieldChanged心不是獲取調用與ListField UI [因爲它適用於按鈕和標籤。]因此,我認爲是不Listfield支持FieldChanged

在navigationClick /的TouchEvent(),寫的動作,你正在編寫FieldChange方法。

相關問題