0

我已经完成了将数据从 android 插入到云中,我想要做的是,我想从云中获取存储的数据(在我的理解中)列出对象“在云中包含字符串数据类型”和将其设置为 TextView 这是我的代码:

package com.cloud.test;

import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //id from the cloud and perfectly working
        Parse.initialize(this, "idp7tOItFQ1TeQ87NqG5okzgsTzBZSfOmTh3LjbJ", "sPlps2HcBLzfBcZTG8uUFPi5gHkGbwFYVGHhGtwd");


    }
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btn1:
            /**
             * this is for inserting data to cloud
             */
            EditText et1 = (EditText)findViewById(R.id.et1);
            EditText et2 = (EditText)findViewById(R.id.et2);
            EditText et3 = (EditText)findViewById(R.id.et3);
            String name = et1.getText().toString();
            int price = Integer.parseInt(et2.getText().toString());
            String desc = et3.getText().toString();
            ParseObject test = new ParseObject("Wardrobe");

            test.put("price", price);
            test.put("name", name);
            test.put("description", desc);
            test.saveInBackground();
            break;

        case R.id.btn2:
            /**
             * below is my problem, i don't know how do i actually get the data from the list
             * which is all String
             */
            ParseQuery query = new ParseQuery("Wardrobe");
            query.whereEqualTo("description", "male");
            query.findInBackground(new FindCallback() {
                @Override
                public void done(List<ParseObject> dataList, ParseException e) {
                    // TODO Auto-generated method stub
                     if (e == null) {
                         TextView tv1 = (TextView)findViewById(R.id.tv1);
                         TextView tv2 = (TextView)findViewById(R.id.tv2);
                         TextView tv3 = (TextView)findViewById(R.id.tv3);
                            /**
                             * here i want to set the data to the TextView to be viewed by the user
                             */
                            Log.d("score", "Retrieved " + dataList.size() + " scores");
                        } else {
                            Log.d("score", "Error: " + e.getMessage());
                        }
                }
            });
            break;
        default:
            break;
        }

    }
}

提前感谢您帮助我

这是我使用的更新String.value(dataList);,我得到的是这个com.parse.ParseObject@44f904b8, com.parse.ParseObject@44f90a30

4

2 回答 2

0
public void done(List<ParseObject> dataList, ParseException e) {
                    // TODO Auto-generated method stub
                     if (e == null) {

                           TextView tv1 = (TextView)findViewById(R.id.tv1);
                        for(int x = 0; x < scoreList.size(); x++)
                        {
                         String d =  scoreList.get(x).getString("name");                         
                         tv1.setText(tv1.getText()+" "+d);
                        }
                            Log.d("score", "Retrieved " + dataList.size() + " scores");
                        } else {
                            Log.d("score", "Error: " + e.getMessage());
                        }
                }
            });
于 2013-02-16T02:37:26.493 回答
0

除非您有一个重写的 toString 方法来打印出不同的东西,否则它会打印出类以及我认为是内存地址或类似的东西。如果你想使用 String.value(或 toString - 同样的东西),你需要重写 ParseObject 的 toString 方法。如果您不想或无权访问该代码,则需要从 ParseObject 类提供的 getter 方法手动构建所需的字符串。

于 2013-02-16T00:28:45.447 回答