Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Joan Marc Sanahuja
PLUS
Joan Marc Sanahuja
Courses Plus Student 12,926 Points

Fill map infoWindow with the data of a ParseUser in android

I'am having problems when filling an infoWindow of a map with data from a ParseUser. I have the objectId from the ParseUser as the title of the marker. Then when clicking on the marker, I want to display an infowindow filling its contents with data from that parseUser. I get the ObjectId from the marker title and then a I do a findInBackground.

This is the code inside the infowindow:

mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
    @Override
    public View getInfoWindow(Marker marker) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public View getInfoContents(Marker marker) {
        View v = getLayoutInflater().inflate(
        R.layout.custom_infowindow, null);
        title = (TextView) v.findViewById(R.id.restaurantName);
        String objectId = marker.getTitle();
        ParseQuery < ParseUser > query = ParseUser.getQuery();
        query.whereEqualTo("restaurant", true);
        query.whereEqualTo("objectId", objectId);
        query.findInBackground(new FindCallback < ParseUser > () {
            public void done(List < ParseUser > objects,
            ParseException e) {
                if (e == null) {
                    if (objects.size() > 0) {
                        for (int i = 0; i < objects.size(); i++) {
                            ParseObject p = objects.get(i);
                            title.setText(p.getString("restaurantname"));
                        }
                    }
                } else {
                    title.setText("merda mes gran");
                }
            }
        });
        return v;
    }
});   

The problem comes when I click on the marker and nothing is displayed inside the infowindow. I think that the problem is in the search of the user and accessing to the data I want, because when I do not do this search and set the title text manually, then I have the text I want in the infowindow when clicking the marker.

I also have tried to change the way of accessing to the item in te objescts list inside the FindCallback but every way has the same result: nothing is displayed in the infowindow.

1 Answer

Joan Marc Sanahuja
PLUS
Joan Marc Sanahuja
Courses Plus Student 12,926 Points

I solved it using a fragment that appears inside a FrameLayout when clicking on a map marker.