在listview中调用listview

bada Programming - Call listview within a listview

本文关键字:listview 调用      更新时间:2023-10-16

我目前有一个包含4个项目的listview,在其中一个listview项目中,我想实现另一个listview,我是否必须做另一个表单管理器?或者我该怎么做呢?另外,如何在另一个类中调用一个类的函数?还是使用引用(指针)将信息从一个类传递到另一个类?

我不确定我完全理解了这个问题。

简而言之,您需要从一个列表视图指向另一个列表视图的指针。如果是在表单中,那么一个指向列表视图的本地指针就足够了。

同样适用于引用类实例:

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