我编写了用单个字符串填充列表视图的代码。但是,我不知道如何填充2个字符串..有人,请帮助我。
这是我的代码:
public class BackTask extends AsyncTask<String, Void, String> {
ArrayList<FlowerAdapter.Flowers> flowersList = new ArrayList<FlowerAdapter.Flowers>();
String url = "http://113.193.30.155/MobileService/MobileService.asmx/GetSampleData";
@Override
protected void onPreExecute(){
super.onPreExecute();
}
@Override
protected String doInBackground(String... strings) {
String content = FlowerAdapter.HttpULRConnect.getData(url);
return content;
}
@Override
protected void onPostExecute(String s){
try {
JSONArray ar =new JSONArray(s);
for (int i = 0; i < ar.length(); i++){
JSONObject jsonObject=ar.getJSONObject(i);
这里我希望得到2个字符串&#34; NAME&#34; &amp; &#34; PERCENTAGE&#34; ....但我不知道如何获取另一个字符串并将其绑定在列表视图。
FlowerAdapter.Flowers flowers= new FlowerAdapter.Flowers();
flowers.setName(jsonObject.getString("NAME"));
flowersList.add(flowers);
FlowerAdapter adapter=new FlowerAdapter(getContext(),R.layout.flower_list_xml,flowersList);
listView = (ListView)getView().findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setVisibility(View.VISIBLE);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:1)
first, add all the field in your Flowers
class with setters and getters
Then set it in the object which you are passing to adapter.
答案 1 :(得分:0)
我为第二个字符串创建了一个setter并将其命名为...那就是所有..
flowers.setPercentage(jsonObject.getString( “百分比”);