gpt4 book ai didi

java - 使用 Parse 后端填充 TextView

转载 作者:行者123 更新时间:2023-12-01 08:52:48 25 4
gpt4 key购买 nike

我正在托管一个解析服务器,其中保存包含植物的数据。我的代码没有错误,但它似乎没有获取任何数据。我希望查询等于“名称”的内容。例如,如果“名称”包含“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();
}
}

最佳答案

使用 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);
}
}
});

关于java - 使用 Parse 后端填充 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42279580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com