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
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus
Accepted Solution

ListItemListener active state behavior

I've been having issues tracking the active state of an item in my list, to keep it highlighted.

 

Basically, when the user presses the item, it's activated after a short period, then when the user slides their finger from the item to over top of the ActionSet that appeared, the ListItem signals activate with the "activate" parameter set to false, and my list item is unhighlighted (because I set it unhighlighted, since this is the only signal I can listen to to determine its no longer being pressed).

 

However, I saw in the documentation that this likely should not be the case:

A list item is "active" while a user is actively pressing the list item or when the item is target for a context menu operation. Once released, or when no longer a context menu target, the item is no longer active. With a StandardListItem, the active visual will have a outline around the item border.

 from the "ListItemListener" docs.

 

This states my item should not call activate with "false" when the user is browsing the attached menu, and should only become inactive when the user is done browsing the menu and releases their finger (which is the behavior I want).

 

I have a suspicion the cause of this is because I am attaching the ActionSet not to the ListItemListener class itself, but to the ListView. Can anybody confirm this is why it is no longer being treated as active, because the ListView has the ActionSet attached, not the ListItemListener?

 

I don't really want to rewrite the code for the ActionSet and move it to a new place if I don't have to, but if it will solve this problem it is well worth it.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: ListItemListener active state behavior

I tried attaching the ActionSet to the ListItem's instead of the ListView. This causes an immediate seg fault whenever the action set would be displayed.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: ListItemListener active state behavior

The ListViewSelection documenatation shows "contextActions" being attached to a ListItemComponent. Surely similar behavior can be achieved wtih a ListItemProvider?

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: ListItemListener active state behavior

Specifically attaching the Action Set to the item in this way causes a seg fault:

 

Item::Item(Container *parent) : CustomControl(parent) {
	Container *itemContainer = new Container(parent);


	/////TESTING AN ACTION SET
	ActionSet *itemActions = new ActionSet();
	itemActions->setTitle("Test Actions");

	ActionItem *testAction = new ActionItem();
	upvoteAction->setTitle("test");
	upvoteAction->setImageSource(QUrl("asset:///images/ic_icon.png"));	

	itemActions->add(testAction);
	itemContainer->addActionSet(itemActions);

	//Set the root of the list item node.
	setRoot(itemContainer);
}

 Item extends CustomControl and ListItemListener.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: ListItemListener active state behavior

[ Edited ]

I attach ActionSet to item in ListItemProvider's updateItem() and connect actions to item's slots.

 

Here is a working code from one of my projects. I hope it helps:

 

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

    MenuDataItem *menuData = data.value<MenuDataItem *>();
    MovableMenuListItem *item = static_cast<MovableMenuListItem *>(listItem);

    item->setTitle(menuData->getTitle());
    item->setDescription(menuData->getDescription());
    QString image = menuData->getImageSource();
    if (!image.isEmpty())
        item->setImageSource(image);
    else
        item->resetImageSource();
item->removeAllActionSets(); int childCount = list->dataModel()->childCount(QVariantList()); //qDebug() << "childCount=" << childCount << ", index=" << indexPath.front().toInt() << "\n"; item->setDataModel(qobject_cast<MenuDataModel *>(list->dataModel())); item->setIndexPath(indexPath); item->addActionSet(ActionSet::create() .title(menuData->getTitle()) .subtitle("Please choose an action") .add(ActionItem::create() .imageSource(QUrl("assets/images/icons/upArrowIcon.png")) .onTriggered(item, SLOT(moveUp())) .enabled(!indexPath.isEmpty() && indexPath.front().toInt() > 0) .title("Move Up")) .add(ActionItem::create() .imageSource(QUrl("assets/images/icons/downArrowIcon.png")) .onTriggered(item, SLOT(moveDown())) .enabled(!indexPath.isEmpty() && indexPath.front().toInt() < childCount-1) .title("Move Down")) .add(DeleteActionItem::create() .onTriggered(item, SLOT(removeFromFavorites())) .title("Remove as Favorite")) ); }

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 206
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: ListItemListener active state behavior

Your code does work... so does mine unfortunately. I had a seg fault in another part of my code :/ I was assuming that wasn't the cause because I got 0 stack trace on the segfault in the debugger. Not sure why I didn't get any sort of stack trace, but it was definitely code unrelated to what I posted seg faulting .

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!