這是我實現ListField的代碼。它創建一個列表;然而,即使我認爲我從vectorFriends
添加了朋友,它仍然是空的。我對開發黑莓應用程序很陌生,所以我確信我的錯誤非常明顯。誰能告訴我爲什麼我的清單是空的?Blackberry:我的ListField實現有什麼問題?
public class HomeScreen extends MainScreen implements FieldChangeListener, ListFieldCallback{
private ListField listFriends;
private Vector vectorFriends;
private Friend _selectedPerson = null;
public HomeScreen(){
vectorFriends = User.getMyUser().getFriends();
this.add(new LabelField("Friends"));
listFriends = new ListField(vectorFriends.size());
listFriends.setCallback(this);
this.add(listFriends)
}
//implemented ListFieldCallback methods
//draw current row
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
Friend personToDraw = (Friend) this.get(list, index);
int drawColor = Color.BLACK;
g.setColor(drawColor);
g.drawText(personToDraw.getFullName(), 0, y, 0, w);
}
// get the selected index from the correct Vector
public Object get(ListField list, int index) {
return vectorFriends.elementAt(index);
}
public void insert(String toInsert, int index) {
vectorFriends.insertElementAt(toInsert, index);
}
public int getPreferredWidth(ListField list) {
return Display.getWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
// Not a correct implementation - this is really just commented out
return start;
}
public int getPreferredWidth(ListField list) {
return Display.getWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
// Not a correct implementation - this is really just commented out
return start;
}
當我創建'listFriends',我設置大小爲'vectorFriends.size()' 。所以我不認爲這是事實。 –
啊我不好,錯過了位... – jprofitt