Esempio n. 1
0
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewWrapper wrap = null;
    View row = convertView;

    if (convertView == null) {
      LinearLayout layout = new LinearLayout(ctxt);
      RatingBar rate = new RatingBar(ctxt);

      rate.setNumStars(3);
      rate.setStepSize(1.0f);

      View guts = delegate.getView(position, null, parent);

      layout.setOrientation(LinearLayout.HORIZONTAL);

      rate.setLayoutParams(
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.FILL_PARENT));
      guts.setLayoutParams(
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT));

      RatingBar.OnRatingBarChangeListener l =
          new RatingBar.OnRatingBarChangeListener() {
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
              rates[(Integer) ratingBar.getTag()] = rating;
            }
          };

      rate.setOnRatingBarChangeListener(l);

      layout.addView(rate);
      layout.addView(guts);

      wrap = new ViewWrapper(layout);
      wrap.setGuts(guts);
      layout.setTag(wrap);

      rate.setTag(new Integer(position));
      rate.setRating(rates[position]);

      row = layout;
    } else {
      wrap = (ViewWrapper) convertView.getTag();
      wrap.setGuts(delegate.getView(position, wrap.getGuts(), parent));
      wrap.getRatingBar().setTag(new Integer(position));
      wrap.getRatingBar().setRating(rates[position]);
    }

    return (row);
  }
Esempio n. 2
0
  @Override
  protected void onFinishInflate() {
    super.onFinishInflate();
    ratingBar = (RatingBar) findViewById(R.id.zrb_rating);
    ratingTv = (TextView) findViewById(R.id.ztv_rating);
    ratingBar.setNumStars(numStars);
    ratingBar.setStepSize(stepSize);
    ratingBar.setMax(max);
    ratingBar.setRating(rating);
    ratingBar.setIsIndicator(isIndicator);
    ratingTv.setTextSize(mTextSize / getResources().getDisplayMetrics().density);
    ratingTv.setTextColor(mTextColor);

    LinearLayout.LayoutParams layoutParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(0, 0, mSpacing, 0);
    ratingBar.setLayoutParams(layoutParams);
  }