使用Parse后端填充TextViews

时间:2017-02-16 16:29:27

标签: java android parsing pfquery

我正在托管一个包含植物数据的Parse服务器。我的代码中没有错误,但它似乎无法获取任何数据。我希望查询等于' name'的内容。例如,如果' name'包含" Daisy"它将找到该花的数据并显示所选信息。这是我的代码:

public class mygardenDetail extends Activity {

String name;
String kgsays;
String care;
String tips;
String image;
ImageLoader imageLoader = new ImageLoader(this);
List<ParseObject> ob;
private List<PlantListitems> plantlist = null;

@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mygarden_detail);


Intent i = getIntent();
name = i.getStringExtra("name");



// Locate the TextViews in singleitemview.xml

TextView txtName = (TextView) findViewById(R.id.name);
TextView txtKGsays = (TextView) findViewById(R.id.KGsays);
TextView txtCare = (TextView) findViewById(R.id.Care);
TextView txtTips = (TextView) findViewById(R.id.Tips);

// Locate the ImageView in singleitemview.xml
ImageView imgflag = (ImageView) findViewById(R.id.image);
txtName.setText(name);


// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
   imageLoader.DisplayImage(image, imgflag);



    try {
    ParseQuery query = new ParseQuery<>("Plants2");
    query.whereMatches("plantName", String.valueOf(equals(name)));
    ob = query.find();

    for (ParseObject country : ob) {
                // Locate images in flag column
                ParseFile image = (ParseFile) country.get("image");

                //PlantListitems map = new PlantListitems();
                txtKGsays.setText((String) country.get("KGsays"));
                txtCare.setText((String) country.get("Care"));
                txtTips.setText((String) country.get("tips"));
                //imgflag.DisplayImage(image.getUrl());
                //plantlist.add(map);
            }
} catch (ParseException e) {
    e.printStackTrace();
}
        } 

1 个答案:

答案 0 :(得分:1)

findInBackground()与回调

一起使用
ParseQuery query = new ParseQuery<>("Plants2");
query.whereEqualTo("plantName", (name));
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> listCountry, ParseException e) {
   for (ParseObject country : listCountry) {
            // Locate images in flag column
            ParseFile image = (ParseFile) country.get("image");

            //PlantListitems map = new PlantListitems();
            txtKGsays.setText((String) country.get("KGsays"));
            txtCare.setText((String) country.get("Care"));
            txtTips.setText((String) country.get("tips"));
            //imgflag.DisplayImage(image.getUrl());
            //plantlist.add(map);
        }
}
});
相关问题