2011-12-07 19 views
0

我目前有一個列表視圖包含4個項目,在其中一個列表視圖項目中,我想實現另一個列表視圖,我必須做另一個窗體管理器嗎?或者我該如何去做呢?另外,如何在另一個類中調用一個類的功能?或者做一個引用(指針)將信息從一個類傳遞到另一個類?bada編程 - 在列表視圖中調用listview

回答

0

不知道我是否理解100%的問題。

總之,你需要從一個列表視圖指向另一個列表視圖。如果你在一個表單中,那麼指向列表視圖的本地指針就足夠了。

同樣適用於引用類實例:

class Apple() { 
    private Basket* basket; 
    public Apple() { 
    basket = null; 
    } 
    public void setBasket(Basket* basket) { 
    this->basket = basket; 
    } 
    public Basket* getBasket() { 
    return this->basket; 
    } 
} 

class Basket() { 
    private Apple* apple; 
    public Basket() { 
    apple = null; 
    } 
    public setApple(Apple* apple) { 
    this->apple = apple; 
    this->apple->setBasket(this); 
    } 
} 

... 
Apple* apple = new Apple(); 
Basket* basket = new Basket() 
basket->setApple(apple); 

希望它可以幫助一點點。

好吧我在這裏加入更多的代碼,看看它是否有助於它沒有經過測試,寫上飛,顯示主要

FormA.h

class FormA : 
    public Osp::Ui::Controls::Form, 
    public Osp::Ui::IItemEventListener 
{ 

    // Other stuff including list 
protected: 
    void OnItemStateChanged (const Osp::Ui::Control &source, int index, int itemId, Osp::Ui::ItemStatus status); 
} 

FormA.cpp

// Other stuff including constructor and list control creation/population 

void FormA::OnItemStateChanged (const Osp::Ui::Control &source, int index, int itemId, Osp::Ui::ItemStatus status) { 

    // Construct and show other form 
    FormB* b = new FormB(itemId); 
    // Add to frame and set formb as current 

} 

FormB.h

class FormA : 
    public Osp::Ui::Controls::Form, 
    public Osp::Ui::IItemEventListener 
{ 
private int itemId; 
public: 
    FormA(int itemId); 
} 

FormB.cpp

FormA::FormA(int itemId) { 
this->itemId = itemId; 
} 

// Now somewhere in your form initialization read the itemId 
// value (this->itemId) and decide what you want to show in the form's list view 
+0

您好,感謝的迴應!我想你明白我的意思。我目前有一個listview。當用戶點擊其中一個項目時,它應該獲取elementID並將elementID傳遞給第二個窗體,以便它知道在第二個窗體中顯示的內容。我真的不知道該怎麼做。我不知道需要包含在.h和.cpp文件中。你可以幫我嗎?謝謝! – Winona

+0

嗨,很高興我明白了這個問題。答案可能是創建一個函數來填充第二個列表視圖,當第一個列表視圖被選中時。如果這個函數在兩個視圖都在同一個窗體上,那麼我沒有看到任何範圍問題,因爲這兩個列表視圖都應該在私有區域中有指針。如果視圖是另一種形式,那麼我猜你只需要將所選元素的id傳遞給第二個視圖來獲取記錄......對不起,但不是一個簡單的答案來描述這裏沒有線條的空間和代碼行:) – George

+0

如在創建一個函數,在第一個窗體中填充第二個窗體?噢,我很迷茫在這個:( – Winona