0

私は以下のようにjsonからandroidにデータをロードするアプリケーションを持っています

public class MainActivity extends Activity {
    private final String URL_SERVICE = "http://92.253.101.239:81/sudandoctors/api.aspx?op=5&GovernorateId=&SpecializationId=&DoctorName=&LastDoctorId=0";
    private final String URL_IMAGE_BASE = "http://92.253.101.239:81/sudandoctors/UploadedFiles/"; 
    TextView tv;
    DoctorInfo doctorObj = new DoctorInfo(); 
    ArrayList<DoctorInfo> doctorsInfoList = new ArrayList<DoctorInfo>();

    ListView lv = (ListView)findViewById(R.id.mylist);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        AsyncHttpClient client = new AsyncHttpClient();

        client.get(URL_SERVICE, new AsyncHttpResponseHandler() {
            @Override
            public void onStart() {
                super.onStart();
                // show loading bar
                Log.d("onStart", "onStart");
            }

            @Override
            public void onSuccess(String response) {
                super.onSuccess(response);
                Log.d("onSuccess", "onSuccess");
                DoctorsModel doctorModel = new DoctorsModel();
                ArrayList<DoctorInfo> doctorsInfoList = new ArrayList<DoctorInfo>();

                try {
                    // convert response to JSON
                    JSONObject json = new JSONObject(response);

                    // get JSON Items
                    doctorModel.setDoctorCnt(json.getInt("DoctorsCount"));
                    doctorModel.setOp(json.getString("op"));

                    JSONArray doctorsArray = json.getJSONArray("Doctors");
                    Log.d("dr arrat", doctorsArray.toString());
                    for (int i = 0; i < doctorsArray.length(); i++) {
                        JSONObject doctorJSON = doctorsArray.getJSONObject(i);


                        doctorObj .setId(doctorJSON.getString("Id"));
                        Log.d("id", doctorJSON.getString("Id"));
                        doctorObj.setName(doctorJSON.getString("DoctorName"));
                        doctorObj.setGovernorateId(doctorJSON.getString("GovernorateId"));
                        doctorObj.setGovernorateName(doctorJSON.getString("GovernorateName"));
                        doctorObj.setSpecializationName(doctorJSON.getString("SpecializationName"));
                        doctorObj.setHospitalId(doctorJSON.getString("HospitalId"));
                        doctorObj.setHospitalName(doctorJSON.getString("HospitalName"));
                        doctorObj.setImageName(URL_IMAGE_BASE + doctorJSON.getString("ImageName"));
                        doctorObj.setMobile(doctorJSON.getString("Mobile"));
                        doctorObj.setSpecializationId(doctorJSON.getString("SpecializationId"));
                        doctorObj.setWeekendDays(doctorJSON.getString("WeekendDays"));
                        doctorObj.setWorkingDays(doctorJSON.getString("WorkingDays"));
                        doctorObj.setWorkingTime(doctorJSON.getString("WorkingTime"));

                        doctorsInfoList.add(doctorObj);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(Throwable e, String message) {
                super.onFailure(e, message);
                // show error message
            }

            @Override
            public void onFinish() {
                super.onFinish();
                // remove loading bar
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                  android.R.layout.activity_list_item);

                // Assign adapter to ListView
                lv.setAdapter(adapter); 
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

そして、リストビューでデータを表示したいのですが、どうすればよいですか?

4

1 に答える 1

1

アダプターを使用する - http://developer.android.com/reference/android/widget/Adapter.html

データを使用してアダプターを作成し、そのアダプターを ListView のアダプターとして設定します。

于 2012-12-16T14:04:58.537 に答える