0

So I'm new to Android and I'm using Parse as my backend. I have an Array column in Parse called PrescriptionArray. I want to take the contents of this array (String values) and populate a listView with them. I think I'm only missing a couple of lines but not sure where? Any help would be greatly appreciated.. Thanks in advance!

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);
            }
            }
        });
    }
}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.