0

Are there any guidelines regarding ratingbars for android? I'm developing an android application and the way I've developed it, I can only set and edit the rating of something by adding it to a dialog box.

I wanted to know if there are any guidelines regarding the ratingbar - is it okay to have it in a dialog box? Or should I do a work-around?

user1397978
  • 255
  • 1
  • 7
  • 24
  • This isn't iOS. You have actual choice on Android, your app will not be rejected for not having the UI work exactly like google may want it. So if you want to put it in a dialog box, go for it. – Gabe Sechan Jul 04 '14 at 21:05
  • Thanks! It's for my Masters and I need to record every UI decision I make in terms of the UI guidelines. If Android says it's not good practice, I can't use it. Which is why I am asking – user1397978 Jul 04 '14 at 21:06
  • Here's the thing- Android doesn't have extensive guidelines like iOS has, in part because of that difference in philosophy. – Gabe Sechan Jul 04 '14 at 21:07
  • Android has excellent [design guidelines](http://developer.android.com/design/index.html) covering just about every part of designing your application, from available components to navigation patterns to typography and writing style. Whether you follow them to the letter is certainly still up to you. – ianhanniballake Jul 04 '14 at 21:23

2 Answers2

1

Per RatingBar's documentation:

A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch/drag or use arrow keys to set the rating when using the default size RatingBar. The smaller RatingBar style (ratingBarStyleSmall) and the larger indicator-only style (ratingBarStyleIndicator) do not support user interaction and should only be used as indicators.

When using a RatingBar that supports user interaction, placing widgets to the left or right of the RatingBar is discouraged.

Editable rating bars are certainly supported and a valid use of RatingBar - a good example is the Google Play Store for rating content.

Community
  • 1
  • 1
ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
0

My concern was having my rating bar within an adapter class (as seen below). I wanted to be able to get the position of the user that the rating bar is linked to. The only work-around I could think of that could do that is by putting it in a dialog box (which is the reason for my question). I solved my problem (of how to access the position from an innner class - ) by making the onRatingChanged by making position in getView to be final. Read here: Making paramters final about final attributes. Is really helpful.

Adapter Class

public class PersonAdapter extends ArrayAdapter<Person> {
private Context context;
private List<Person> people;

public PersonAdapter(Context context, List<Person> people) {
    super(context, R.layout.person_layout, people);
    this.context = context;
    this.people = people;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) 
{
    // if this is a new view, then inflate it
    View personView = convertView;

    if (personView == null) 
    {
        // get the inflater that will convert the person_layout.xml file
        // into an actual object (i.e. inflate it)
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // create a view to display the person's info
        personView = inflater
                .inflate(R.layout.person_layout, parent, false);

        TextView txt1stTime = (TextView) personView
                .findViewById(R.id.txt1stTime);
        txt1stTime.setText("1st time");
    } 
    else 
    {
        TextView txt1stTime = (TextView) personView
                .findViewById(R.id.txt1stTime);
        txt1stTime.setText("Recycled");
    }

    // keep track of person this view is working with
    personView.setTag(people.get(position));

    // get text views that will hold strings
    TextView txtSurname = (TextView) personView
            .findViewById(R.id.txtSurname);
    TextView txtFirstname = (TextView) personView
            .findViewById(R.id.txtFirstname);
    RatingBar ratingBar = (RatingBar) personView
            .findViewById(R.id.ratingBar1);


     //Once selected, get the question which the rating is in 
    //Start asynctask and get all the details for that question to update
    //Send and update rating
    ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
    {
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
        {
            ratingBar.setRating(rating);
            String name = people.get(position).surname;
            Toast.makeText(getContext(),
                    "Rating set to:  " + rating + " for the position: " + position + " and user: " + name, Toast.LENGTH_SHORT).show();   

        }
    });

    // set text fields
    txtSurname.setText(people.get(position).surname);
    txtFirstname.setText(people.get(position).firstName);

    float rate = ratingBar.getRating();
    Toast.makeText(getContext(),
            "Rating is: " + rate, Toast.LENGTH_LONG).show();
    people.get(position).rating = rate;
    System.out.print(people.get(position).rating);
    // return view to ListView to display
    return personView;
}

I know my answer is not directly linked to my actual question, but if anyone ever comes across the same problem of rather using a dialog box, there is a solution.

Community
  • 1
  • 1
user1397978
  • 255
  • 1
  • 7
  • 24