使用Android平台更新parse.com中每行的值 [英] updating values per row in parse.com using android platform

查看:40
本文介绍了使用Android平台更新parse.com中每行的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新名为parse.com的云存储站点中的每行值时遇到问题。我只是使用parse.com的新手。我已阅读有关文档并了解它。但是我想做的和那里的例子有些不同。这是我的代码。

I have a problem with updating values per row in a cloud storage site called parse.com. I am only a newbie in using parse.com. I have read the documentation about it and have understand it. But what I want to do is a little bit different from the example there. Here's my code..

public void onClick(View arg0) {
    if (arg0.getId() == R.id.button1) {
        ParseQuery query = new ParseQuery("inventory");
        query.findInBackground(new FindCallback() {

              public void done(List<ParseObject> test, ParseException e) {

                  ParseObject testObject = new ParseObject("inventory");
                  if(e==null) { 
                      String str="";
                      String str2="";
                      for(int x =0;x<test.size();x++){
                          str = test.get(x).getString("name");
                          str2 = test.get(x).getString("quantity");
                          if (!str.equals(et1.getText().toString())){
                             str = "";
                          }
                          if(str.equals(et1.getText().toString()))
                          {


                                      testObject.put("quantity", et2.getText().toString());
                                      testObject.saveInBackground();

                              x = test.size();
                          }
                          else{
                              tv1.setText("error" + e.getMessage());
                          }
              }


                  }}

        });

    } }

我想更新商品名称的数量我已经输入了。当我输入的内容等于云上的名称时,它将更新另一列,该列引用我输入的产品名称。但是由于我的代码,它创建了一个新行,而不是更新现有行..我的代码中缺少/错误的是什么?有人可以帮帮我吗? :) 提前致谢! :)

I want to update the quantity of the product name that i have inputted. when my input is equal to the name on the cloud it will update the other column which refers to the product name that I have inputted. But as a result of my code, it creates a new row, instead of updating the existing row.. what is lacking/wrong in my code? can someone please help me? :) thanks in advance! :)

推荐答案

我正在解决相同的问题。我发现

I'm figuring out the same problem. I have found this:

答案是要更新现有对象,您需要首先对其进行检索。其网站上的文档中提供了检索方法。

The answer says to update an existing object, you need to retrieve it first. The retrieve method is given in the documentation on their website.

编辑:
完成!这是您的操作方式;首先获取对象,然后通过update方法更新所需的值。

Done! Here is how you do it; first fetch the object and then update the values you want to through the update method.

ParseQuery query = new ParseQuery("UserName");
            query.getInBackground("GKIp4pxBrF", new GetCallback() {
              public void done(final ParseObject object, ParseException e) {
                if (e == null) {

                    object.put("Name", username);
                    object.saveInBackground(new SaveCallback() {
                    public void done(ParseException e) {

                    object.put("Name", oldname);

                }
              });

             }

                else { 
                 e.printStackTrace();
                }

        }
});

如果您不事先知道对象代码,建议您遍历所需的行查询

In case you don't know the object code before hand, I suggest you find the required row through a query.

这篇关于使用Android平台更新parse.com中每行的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆