Example #1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    RestaurantHolder holder;
    if (row == null) {
      LayoutInflater inflater =
          (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      row = inflater.inflate(layoutResourceId, parent, false);

      holder = new RestaurantHolder();
      holder.title = (TextView) row.findViewById(R.id.listItemTitle);
      holder.rating = (RatingBar) row.findViewById(R.id.listItemRating);
      holder.icon = (ImageView) row.findViewById(R.id.listItemIcon);
      holder.price = (TextView) row.findViewById(R.id.listItemPrice);
      row.setTag(holder);
    } else {
      holder = (RestaurantHolder) row.getTag();
    }
    Restaurant mRestaurant = filtered.get(position);
    holder.title.setText(mRestaurant.getName());
    holder.rating.setRating((float) mRestaurant.getAvgRating());

    if (mRestaurant.getImage() != null) holder.icon.setImageBitmap(mRestaurant.getImage());
    else holder.icon.setImageResource(R.drawable.woww_logo_xxx);

    // Set price with $ signs
    String price = "";
    for (int i = 0; i < mRestaurant.getPriceLevel() + 1; ++i) {
      price += "$ ";
    }

    // if no price was retrieved from this restaurant
    if (mRestaurant.getPriceLevel() == 10) {
      // Change to sentinel value -- pushes unknown prices to the bottom
      holder.price.setText("???");
    } else holder.price.setText(price);

    return row;
  }
    @Override
    public void bindView(View row, Context ctxt, Cursor c) {
      RestaurantHolder holder = (RestaurantHolder) row.getTag();

      holder.populateFrom(c, helper);
    }