Ashok
Ashok

Reputation: 637

How can i update the record in dropbox programatically in android?

I am integrating dropbox to my android app its working fine but, i am facing the one problem .I am insert the one record programatically record inserted dropbox its worked fine .

How to update data in dropbox.

I am using the following code to insert dropbox

    DbxFields taskFields = new DbxFields();
    taskFields.set("completed", false);
    taskFields .set("taskname", taskName);
    taskFields.set("taskaddress", taskaddress);
    taskFields.set("taskphone", taskPhone);
    taskFields.set("created", new Date());
    mTable.insert(taskFields);
    mDatastore.sync();

i dn't know how to update the above inserted record.please guide me anyone know.Adavance thanks to all

Upvotes: 1

Views: 112

Answers (1)

reVerse
reVerse

Reputation: 35264

Let's take the following example and let's assume that you want to change the completed-value of the task with the name XYZ to true.

    DbxTable mTable = store.getTable("YOUR_TABLE_NAME");
    DbxFields mQueryFields = new DbxFields();
    mQueryFields.set("taskname", "XYZ");
    try {
        QueryResult mResults = mTable.query(mQueryFields);
        Iterator<DbxRecord> iter = mResults.iterator();
        while (iter.hasNext()) {
            DbxRecord record = iter.next();
            DbxFields mUpdateFields = new DbxFields();
            mUpdateFields.set("completed", true);
            record.setAll(mUpdateFields);
        }
    } catch (DbxException e) {
        e.printStackTrace();
    }
    store.sync();

Note: Since I'm using a while-loop this code would change the completed-value of all tasks named "XYZ"

Edit

If you try to edit only one property there's actually no need to create sa new DbxFieldsobject, just call this:

record.set(PROPERTY, VALUE);
story.sync();

Upvotes: 1

Related Questions