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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


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
Highlighted
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!