Java Code Examples for android.widget.RatingBar#setStepSize()

The following examples show how to use android.widget.RatingBar#setStepSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KinoListAdapter.java    From CineLog with GNU General Public License v3.0 5 votes vote down vote up
private void initRating(View convertView, RatingBar kinoRatingRatingBar, KinoDto movie) {
    TextView kinoRatingRatingBarAsText = (TextView) convertView.findViewById(R.id.main_result_kino_rating_bar_as_text);
    TextView kinoRatingRatingBarMaxAsText = (TextView) convertView.findViewById(R.id.main_result_kino_rating_bar_max_as_text);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    int maxRating;
    if (movie.getMaxRating() == null) {
        String defaultMaxRateValue = prefs.getString("default_max_rate_value", "5");
        maxRating = Integer.parseInt(defaultMaxRateValue);
    } else {
        maxRating = movie.getMaxRating();
    }

    if (maxRating <= 5) {
        kinoRatingRatingBarAsText.setVisibility(View.INVISIBLE);
        kinoRatingRatingBarMaxAsText.setVisibility(View.INVISIBLE);
        kinoRatingRatingBar.setVisibility(View.VISIBLE);

        kinoRatingRatingBar.setStepSize(0.5f);
        kinoRatingRatingBar.setNumStars(maxRating);

        if (movie.getRating() != null) {
            kinoRatingRatingBar.setRating(movie.getRating());
        } else {
            kinoRatingRatingBar.setRating(0);
        }
    } else {
        kinoRatingRatingBar.setVisibility(View.INVISIBLE);
        kinoRatingRatingBarAsText.setVisibility(View.VISIBLE);
        kinoRatingRatingBarMaxAsText.setVisibility(View.VISIBLE);

        kinoRatingRatingBarAsText.setText(String.format("%s", movie.getRating()));
        kinoRatingRatingBarMaxAsText.setText(String.format("/%s", maxRating));
    }
}