I have a RecyclerView whose adapter fetches details about a place ID using the Google Places API. The adapter then displays those details (eg. place address) in each element of the RecyclerView.
Is there a recommended way to achieve this asynchronously? In my current solution, the place addresses are sometimes displayed in the incorrect RecyclerView element when the user scrolls up or down. Also when tapping on a RecyclerView element to go to the detail screen, then going back to the original screen, some of the place addresses are missing in the RecyclerView (presumably there is a delay when the details are still being fetched from the Places API).
public void onBindViewHolder(final ViewHolder v, int position) {
Places.GeoDataApi.getPlaceById(googleApiClient, placeID)
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
Place place = places.get(0);
// Display address in the RecyclerView element
v.address.setText(place.getName());
}
}