1

I have two classes in Parse.com

1- called HospitalAppointment which have list of appointments and each object has (AppointmentDate (date) , DoctorFile (pointer (to class Doctors) ) and other ... )

2- class called Doctor ( has doctor name ( string) , ID .. other info )

and I have 2 java classes in android studio

1- my main activity in this class I do query for class HospitalAppointment

    ParseQuery<ParseObject> doctors = ParseQuery.getQuery("HospitalAppointment");
    doctors.whereEqualTo("AppointmentDate",startDate);
     doctors.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> status, com.parse.ParseException e) {
            if (status == null) {
                 Log.d("score", "no doctor available: ");
            } else {
                mStatus = status;
                DoctorAdapter adapter = new DoctorAdapter(getListView().getContext(), mStatus);
                setListAdapter(adapter);
            }
        }
    });

and in the DoctorAdapter activity where I write the function for the listview is the problem

public class DoctorAdapter extends ArrayAdapter<ParseObject> {
protected Context mContext;
protected List<ParseObject> mStatus;

public DoctorAdapter(Context context, List<ParseObject> status) {
    super(context, R.layout.doctor_listadapter, status);
    mContext = context;
    mStatus = status;
}


//getview used to inflate each row
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(
                R.layout.doctor_listadapter, null);
        holder = new ViewHolder();//create new view
        holder.mDocName = (TextView) convertView.findViewById(R.id.doctorName);//very imp to convertview
         holder.mDocId = (TextView) convertView.findViewById(R.id.doctorId);

        convertView.setTag(holder);//holder as parameter
    } else {
        holder = (ViewHolder) convertView.getTag();

    }

    ParseObject statusObject = mStatus.get(position);//postition of that row


    ParseObject getDoctorID = statusObject.getParseObject("DoctorName");
    String docId= getDoctorID.getObjectId();
    holder.mDocId.setText(docId);


    *// here is the problem I cannot retrive the Pointer data like Doctor name*


    return convertView;
}

public static class ViewHolder {

     TextView mDocId;
    TextView mDocName;
}}    

I retrieve the object Id but the problem in the pointer I can't get any data from the pointer I try the query method I call the class name "Doctors" and I do find the "ID of the doctor to get his name but it doesn't work

and I try doing Parse object and I get this object but also not work ?

I hope you can help me

2 Answers 2

1

try like this

ParseObject hospitalAppointment = mStatus.get(position);//postition of that row

ParseObject doctor  = hospitalAppointment.getParseObject("columnName");
doctor.fetchIfNeededInBackground(new GetCallback<ParseObject>() {
    public void done(ParseObject doctor, ParseException e) {
        String docId= doctor.getObjectId();
      // Do something with your new title variable
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

I was facing the same problem. In fact I had a hierarchy of classes like ClassA has a field listPointerB which has a list of pointers to a ClassB and ClassB has a field listPointerC which has a list of pointers to a ClassC.

If I want to fetch all the data, I do the following.

ParseQuery<ClassA> query = ParseQuery.getQuery(ClassA.class);
query.include("modules");
query.include("modules.lessons");
query.findInBackground(...);

If you look at the documentation of include() method, it says that you can use to '.' provide nesting of the fields and this works fine for me. Amazing thing is that, it also works with the list. What it basically does is, when you say that you want to include a fields, it fetches that object and puts it into the payload.

For your case, you should do like:

ParseQuery<ParseObject> doctors = ParseQuery.getQuery("HospitalAppointment");
doctors.whereEqualTo("AppointmentDate",startDate);
doctors.include("DoctorFile");
doctors.findInBackground(...);

Comments

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.