如何使用ArrayAdapter使用Parse数组填充ListView

时间:2016-01-27 16:51:04

标签: android arrays listview parse-platform android-arrayadapter

所以我是Android的新手,我正在使用Parse作为我的后端。我在Parse中有一个名为PrescriptionArray的Array列。我想获取此数组的内容(字符串值)并使用它们填充listView。我想我只是错过了几行,但不确定在哪里?任何帮助将不胜感激..提前致谢!

public class PrescriptionsArrayActivity extends AppCompatActivity {

private ListView lvPrescriptions;
private EditText etMedicalID;
private ArrayAdapter<String> adapter ;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_prescriptions_array);

    lvPrescriptions = (ListView) findViewById(R.id.lvPrescriptions);
    etMedicalID = (EditText) findViewById(R.id.etMedicalID);

    //Get the Medical ID number from previous activity
    Bundle bundle = getIntent().getExtras();
    String str = bundle.getString("MedicalID");
    Toast.makeText(getBaseContext(), str, Toast.LENGTH_LONG).show();
    etMedicalID.setText(str);

    final List<String> arrayprescription = new ArrayList<String>();
    final ArrayAdapter adapter = new ArrayAdapter(PrescriptionsArrayActivity.this, android.R.layout.simple_list_item_1, arrayprescription);

    final ParseQuery<ParseObject> query = ParseQuery.getQuery("PrescriptionObject");
    query.whereEqualTo("MedicalID", etMedicalID.getText().toString());
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> prescriptionList, ParseException e) {

            if (e == null) {
                for (int i = 0; i < prescriptionList.size(); i++) {
                    ParseObject p = prescriptionList.get(i);
                    if (p.getList("PrescriptionArray") != null) {

                            String s = arrayprescription.toString();
                            adapter.addAll(Arrays.asList(s));


                    }
                }
                lvPrescriptions.setAdapter(adapter);
            }
            }
        });
    }
}

0 个答案:

没有答案