多个JSONObject jo

时间:2016-10-20 23:34:56

标签: android json android-layout

我需要多个JSONObject jo 我想在两个文本中显示两个数组

示例:                                 String objectno = jo.getString(" table1");                                 String objectno = jo2.getString(" table2");

代码

public class MainActivity extends Activity {

String url = "url";
ProgressDialog PD;

ArrayList<String> countries;

ArrayAdapter<String> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ListView listView=(ListView)findViewById(R.id.list);
    countries=new ArrayList<String>();

    adapter = new ArrayAdapter(this,R.layout.items, R.id.tv, countries);

    listView.setAdapter(adapter);

    //countries = new ArrayList<String>();

    PD = new ProgressDialog(this);
    PD.setMessage("Loading.....");
    PD.setCancelable(false);


    MakeJsonArrayReq();
}

private void MakeJsonArrayReq() {
    PD.show();

    JsonArrayRequest jreq = new JsonArrayRequest(url,
            new Response.Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray response) {

                    for (int i = 0; i < response.length(); i++) {
                        try {
                            JSONObject jo = response.getJSONObject(i);
                            String objectno = jo.getString("objectno");
                            countries.add(objectno);

                        } catch (JSONException e) {
                            e.printStackTrace();

                        }
                    }
                    PD.dismiss();
                    adapter.notifyDataSetChanged();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });

    MyApplication.getInstance().addToReqQueue(jreq, "jreq");
}

}

我需要得到,

  

String objectno = jo.getString(&#34; objectno&#34;);

// AND  String objectno = jo.getString(&#34; drivername&#34;);

布局项目:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginBottom="4dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginTop="4dp"
        android:src="@drawable/iconlist" />

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:paddingTop="6dp"/>

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

请需要协助。

0 个答案:

没有答案