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: 148
Registered: ‎01-08-2013
My Device: 9860
My Carrier: Airtel

Listview single item update

Hi All,

     I want to update single item in listview.The listview item only contain a  imageview and a labe field.  But when click on listview it doesnt work. My code is copy from http://supportforums.blackberry.com/t5/Cascades-Development/Unable-to-render-the-ListComponent-Image...

 

   Thanks & Regards

         Sanjit

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Listview single item update

Could you show  the code your are trying to run ?

Developer
Posts: 148
Registered: ‎01-08-2013
My Device: 9860
My Carrier: Airtel

Re: Listview single item update

main.qml

Page {
    content: Container {
        ListView {
            objectName: "listView"
            listItemComponents: [
                ListItemComponent {
                    type: "header"
                    HeaderListItem {
                        title: ListItemData
                    }
                },
                ListItemComponent {
                    type: "item"
                    StandardListItem {
                        id: root
                        title: ListItemData.firstname
                        description: ListItemData.surname
                        imageSource: ListItemData.imagepath
                    }
                }
            ]
        }
    }
}

 .hpp

// Default empty project template
#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_

#include <QObject>
#include <bb/cascades/ListView>
#include <bb/cascades/QListDataModel>
using namespace bb::cascades;
namespace bb { namespace cascades { class Application; }}

/*!
 * @brief Application pane object
 *
 *Use this object to create and init app UI, to create context objects, to register the new meta types etc.
 */
class ApplicationUI : public QObject
{
    Q_OBJECT
public:
    ApplicationUI(bb::cascades::Application *app);
    virtual ~ApplicationUI() {}
public slots:
	void onSelectionChanged(const QVariantList indexPath, bool selected);

private:
	ListView *listView;
};


#endif /* ApplicationUI_HPP_ */

 .cpp

// Default empty project template
#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/GroupDataModel>
using namespace bb::cascades;

ApplicationUI::ApplicationUI(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    GroupDataModel *model = new GroupDataModel(
    			QStringList() << "firstname" << "surname" << "imagepath");
    	model->setGrouping(ItemGrouping::ByFirstChar);

    	listView = root->findChild<ListView *>("listView");

    	QVariantMap person;
    	person["firstname"] = "John";
    	person["surname"] = "Mark";
    	person["imagepath"] = "I will set on click.";
    	model->insert(person);
    	person["firstname"] = "Mark";
    	person["surname"] = "Russie";
    	person["imagepath"] = "asset:///icon.png";
    	model->insert(person);

    	listView->setDataModel(model);

    	QObject::connect(listView,
    			SIGNAL(selectionChanged(const QVariantList, bool)), this,
    			SLOT(onSelectionChanged(const QVariantList, bool)));

    // set created root object as a scene
    app->setScene(root);
}

void ApplicationUI::onSelectionChanged(const QVariantList indexPath, bool selected) {
    if (selected) {
        if (sender()) {
            GroupDataModel *stampModel =
                    (GroupDataModel *) listView->dataModel();
            QVariantMap map = stampModel->data(indexPath).toMap();
            //map["imagepath"] = "asset:///icon.png";
            map["imagepath"] = "../../../data/icon.png";
            stampModel->updateItem(indexPath, map);
//            fprintf(stderr, "\nSelection Called");
        }
    }
}

 

Highlighted
Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Listview single item update

Maybe the path for the image is not correct...

Use QDir::homePath(). Check http://developer.blackberry.com/cascades/reference/qdir.html