title: Add places API data in RecyclerView
body: <p>I am working on an android app that get places around the user and display it to him. I want to present the places to him on a <code>CardLayout</code> using the <code>RecyclerView</code> in a fragment. I tried to implement these but when I run the app on my device , it displays just a blank page while in the Logcat, it shows the names of places around me. I don't really know if my implementation of <code>viewadapter</code> is the problem..Please need help. Here is the fragment and <code>placesadapter</code> Class.</p>
  
  <pre><code>public class CardFragment extends Fragment implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks {
      private static final String LOG_TAG = "CardFragment";
      protected GoogleApiClient mGoogleApiClient;
      private static final int PERMISSION_REQUEST_CODE = 100;
      PlacesAdapter adapter = null;
      RecyclerView lstPlaces;
      private ArrayList&lt;Place&gt; place = new ArrayList&lt;&gt;();
      public CardFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // addPlaces();
  
          mGoogleApiClient = new GoogleApiClient.Builder(getContext())
                  .addConnectionCallbacks(this)
                  .addOnConnectionFailedListener(this)
                  .addApi(LocationServices.API)
                  .addApi(Places.PLACE_DETECTION_API)
                  .addApi(Places.GEO_DATA_API)
                  .build();
          mGoogleApiClient.connect();
  
          adapter = new PlacesAdapter(place);
          retrievePlaces();
  
      }
  
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.card_fragment, container, false);
          // Inflate the layout for this fragment
          lstPlaces = (RecyclerView)rootView.findViewById(R.id.list_places_recyclerview);
  
          lstPlaces.setLayoutManager(new LinearLayoutManager(getActivity()));
          lstPlaces.setAdapter(adapter);
          return rootView;
  
      }
      // Handle the result from requested permissions.
      @Override
      public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],@NonNull int[] grantResults) {
          switch (requestCode) {
              case PERMISSION_REQUEST_CODE:
                  if ((grantResults.length &gt; 0) &amp;&amp; (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                      Log.i("Permision", "permission granted");
                  }
                  break;
          }
      }
      //Handle onConnectionFailed
      @Override
      public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
          Log.e(LOG_TAG, "Google Places API connection failed with error code: " + connectionResult.getErrorCode());
          Toast.makeText(getActivity(), "Google Places API connection failed with error code:" + connectionResult.getErrorCode(), Toast.LENGTH_LONG).show();
      }
  
      private void retrievePlaces() throws SecurityException {
  
          PendingResult&lt;PlaceLikelihoodBuffer&gt; result = Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
          result.setResultCallback(new ResultCallback&lt;PlaceLikelihoodBuffer&gt;() {
              @Override
              public void onResult(@NonNull PlaceLikelihoodBuffer likelyPlaces) {
  
                  for (PlaceLikelihood placeLikelihood : likelyPlaces) {
                      place.add(placeLikelihood.getPlace());
                      Log.i("Place = ",  placeLikelihood.getPlace().getName().toString());
                  }
  
                  likelyPlaces.release();
              }
          });
  
      }
  
      @Override
      public void onConnected(@Nullable Bundle bundle) {
  
              int hasPermission = 0;
  
              hasPermission = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION);
              if (hasPermission != PackageManager.PERMISSION_GRANTED) {
                  ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_CODE);
              } else {
                  Log.i("Client Connection", "Connected to GoogleClient");
              }
  
  
      }
  
      @Override
      public void onConnectionSuspended(int i) {
  
      }
  
  
  }
  </code></pre>
  
  <p>PlaceAdapter</p>
  
  <pre><code>public class PlacesAdapter extends RecyclerView.Adapter &lt;PlacesAdapter.PlaceViewHolder&gt;{
  
      private ArrayList&lt;Place&gt; places = new ArrayList&lt;&gt;() ;
  
      public PlacesAdapter(ArrayList&lt;Place&gt; places){
          this.places = places;
      }
  
  
      @Override
      public PlaceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_item, parent, false);
          return new PlaceViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(PlaceViewHolder holder, int position) {
          holder.placeName.setText(places.get(position).getName().toString());
          holder.telephone.setText(places.get(position).getPhoneNumber().toString());
          holder.adress.setText(places.get(position).getAddress().toString());
          holder.location.setText(places.get(position).getLocale().getDisplayName());
          holder.website.setText((CharSequence) places.get(position).getWebsiteUri().toString());
          //holder.placeName.setText( places.get(position).getTelephone());
      }
      @Override
      public void onAttachedToRecyclerView(RecyclerView recyclerView) {
          super.onAttachedToRecyclerView(recyclerView);
      }
      @Override
      public int getItemCount() {
          return places.size();// places.size();
      }
  
      public static class PlaceViewHolder extends RecyclerView.ViewHolder{
          TextView placeName;
          TextView telephone;
          TextView adress;
          TextView location;
          TextView website;
          CardView cardView;
  
  
          public PlaceViewHolder(View itemView) {
              super(itemView);
              cardView = (CardView) itemView.findViewById(R.id.card_view);
              placeName = (TextView)itemView.findViewById(R.id.place_name);
              telephone = (TextView)itemView.findViewById(R.id.telephone);
              adress = (TextView)itemView.findViewById(R.id.adress);
              location = (TextView)itemView.findViewById(R.id.location);
              website = (TextView)itemView.findViewById(R.id.website);
          }
      }
  }
  `
  </code></pre>