Reputation: 11
So I'm trying to retrieve the values stored in the PrescriptionArray column in Parse, which is an Array. I then want to display these values in the ListView lvPrescriptions. Any help would be greatly appreciated!!
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) {
final List<String> arrayprescription = new ArrayList<String>();
for (int i = 0; i < prescriptionList.size(); i++) {
ParseObject p = prescriptionList.get(i);
if (p.getList("PrescriptionArray") != null) {
arrayprescription.addAll(Arrays.asList("PrescriptionArray"));
ArrayAdapter adapter = new ArrayAdapter(PrescriptionsArrayActivity.this, android.R.layout.simple_list_item_1, arrayprescription);
lvPrescriptions.setAdapter(adapter);
}
Upvotes: 1
Views: 831
Reputation: 716
public void done (List < ParseObject > prescriptionList, ParseException e){
if (e == null) {
final List<String> arrayprescription = new ArrayList<String>();
for (ParseObject p : prescriptionList) {
if (p.getList("PrescriptionArray") != null) {
for(Prescription prescriptionObject: p.getList("PrescriptionArray")) {
arrayprescription.add(prescriptionObject.getPropertyName());
}
}
}
ArrayAdapter adapter = new ArrayAdapter(PrescriptionsArrayActivity.this, android.R.layout.simple_list_item_1, arrayprescription);
lvPrescriptions.setAdapter(adapter);
}
}
Note that PrescriptionArray
should contain a list of objects where you can access to their properties using getter methods of the object (or getting properties directly if its a Json), then because you are using an ArrayAdapter and not creating your own, you have to populate the ArrayAdapter data with String
objects.
Upvotes: 0
Reputation: 695
Try moving the setting of the listview and adapter outside of the parse query and then adding each item to the adapter. Also, do not know why you are creating/setting a list in the query.
ArrayAdapter adapter = new ArrayAdapter(PrescriptionsArrayActivity.this, android.R.layout.simple_list_item_1, arrayprescription);
lvPrescriptions.setAdapter(adapter);
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) {
final List<String> arrayprescription = new ArrayList<String>();
for (int i = 0; i < prescriptionList.size(); i++) {
ParseObject p = prescriptionList.get(i);
adapter.add(stateList.get(i));
}
Upvotes: 0