2017-02-16 31 views
0

我正在托管一个保存包含植物数据的解析服务器。我的代码中没有错误,但似乎没有获取任何数据。我希望查询等于'name'的内容。例如,如果'名称'包含“雏菊”,它会找到该花的数据并显示选定的信息。这里是我的代码:使用解析后端填充TextViews

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(); 
} 
     } 
+0

什么是正确的,现在发生了什么?不清楚的问题。 –

+0

现在发生了什么?好吧,就像我说过的,它没有显示任何错误,但是不会从后端获取任何数据并在textviews中显示 – user4682589

+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); 
     } 
} 
});