2017-02-16 53 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); 
     } 
} 
});