Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Capture a button press from a list?

I have a list with a list provider, this creates a button for each element in my list.

 

My question is, how can I capture a press of this button in the class that creates the list?

 

Thanks

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: Capture a button press from a list?

Bump 

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Capture a button press from a list?

from yourlist item component, you can access your listview as follows:

 

'listItemComponentId'.ListItem.view.customFunctionInListView()

ListView{
  function customFunctionInListView(){
  }
}

 

Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: Capture a button press from a list?

Sorry this does not answer my question, I want to capture a button press in the class that creates the list, from a button that is in the list.

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Capture a button press from a list?

well mind giving an example or code sample?? clearly we don't understand your request...

 

a button has an onClick event...maybe thats what you are looking for?

 

ListItemComponent{
 Button {
  onClick: {
  }
 }
}

 

Super Contributor
Posts: 440
Registered: ‎01-13-2011
My Device: Playbook
My Carrier: NA

Re: Capture a button press from a list?

 

Shop Class

ListView *listView = new ListView();
DrumShopFactory *drumShopFactory = new DrumShopFactory();

GroupDataModel *model = new GroupDataModel();

QVariantMap map = QVariantMap();
map["title"] = QString("One");
model << map;
map["title"] = QString("Two");	
model << map;

listView->setDataModel(model);
listView->setListItemProvider(drumShopFactory);

 DrumShopFactory Class:

 

VisualNode * DrumShopFactory::createItem(ListView* list, const QString &type)
{

  // We only have one item type so we do not need to check the type variable
  Q_UNUSED(type);
  Q_UNUSED(list);

  DrumShopItem *drumShopItem = new DrumShopItem();

  return drumShopItem;
}

void DrumShopFactory::updateItem(ListView* list, bb::cascades::VisualNode *listItem, const QString &type, const QVariantList &indexPath, const QVariant &data)
{
  Q_UNUSED(list);
  Q_UNUSED(indexPath);
  Q_UNUSED(type);

  // Update the control with correct data
  QVariantMap map = data.value<QVariantMap>();
  DrumShopItem *drumShopItem = static_cast<DrumShopItem *>(listItem);
  drumShopItem->updateItem(map["title"].toString());



}

 DrumShopItem Class:

 

DrumShopItem::DrumShopItem(Container *parent) : CustomControl(parent)
{
   //OTHER LAYOUT STUFF NOT DISPLAYED FOR FORUM POST
   
//Button QString buttonText = "Buy"; button = new Button(); button->setText(buttonText);
contentContainer->add(button);

}

 

My question is, I want to invoke a method in my Shop Class, from the button in my DrumShopItem class.

 

I've tried sending a signal out from the button but the list view won't bubble it out because the signal does not exists in a list view compnent.

 

How can I do this in C++?

--------------------------------------------------------------------------------------------------
BlackBerry Apps: Instruments | ARTPAD | Piano | Drums | Xylophone
Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Capture a button press from a list?

well i already gave you the solution to that in my first reply, at least in QML.

 

To do that in C++, it should be similar....i'm not very familiar with the c++ side of things but my guess would be:

 

1)  extend ListView class to provide a custom function:

handleButtonClick(...params...)

 

2) in your DrumShopFactory and DrumpShopItem, make sure than your DrumShopItem keeps the reference to the ListView object

DrumShopItem *drumShopItem = new DrumShopItem();
drumpShopItem->setListView(listView);

 

3) in your DrumShopItem, connect the click() signal of your Button to a slot (let's call the slot: onClick()) in your drumShopItem. then in your onClick() slot, call the custom function in your custom list view object

void DrumShopItem::onClick|() 
{
  listView->handleButtonClick(...params...)
}

 

Your ListItemComponent has its own scope and as such do not have access to anything outside its own scope. So to solve this, you keep a pointer to the ListView where you added some custom function...in QML you could do that by calling component.view.customFunc()

 

i haven't tested this as i'm not familiar with how to use cascades in c++ but im fairly confident this should work!

 

good luck!