Skip to content

Instantly share code, notes, and snippets.

@VaidotasK
Created July 14, 2018 12:43
Show Gist options
  • Save VaidotasK/65566c263a49b8aaf720bf1ab5189a90 to your computer and use it in GitHub Desktop.
Save VaidotasK/65566c263a49b8aaf720bf1ab5189a90 to your computer and use it in GitHub Desktop.
From PlaceAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_place, parent, false);
}
// Get the {@link Place} object located at this position in the list
Place currentPlace = getItem(position);
TextView placeNameTextView = convertView.findViewById(R.id.place_name_textView);
placeNameTextView.setText(currentPlace.getPlaceName());
ImageView placeImageImageView = convertView.findViewById(R.id.place_image_imageView);
if (currentPlace.hasImage()) {
placeImageImageView.setImageResource(currentPlace.getPlaceImageResourceId());
placeImageImageView.setVisibility(View.VISIBLE);
} else {
placeImageImageView.setVisibility(View.GONE);
}
TextView placeAddressTextView = convertView.findViewById(R.id.place_address_textView);
placeAddressTextView.setText(currentPlace.getPlaceAddress());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment