我想使用评分栏显示用户的分数。
例如,如果用户在 30 个问题中答对了 7 个问题,则文本视图 (tv_percentage) 的正确显示率为 23.33%,而评级星级则应显示 5 颗星中的 1.17 颗星,但现在无论分数是多少,总是显示 5 颗星。
下面的事情我做错了什么?
Code:
SharedPreferences score = this.getSharedPreferences("MyApp", 0);
int userscore = score.getInt("score", 0);
int userQnumber = score.getInt("number_of_question_to_selected", 9999);
double scoring100 = Double.valueOf(userscore) / Double.valueOf(userQnumber) *100;
String stripped2 = Double.valueOf(scoring100).toString();
DecimalFormat myFormatter1 = new DecimalFormat("###,###,###.##");
stripped2 = myFormatter1.format(Double.valueOf(stripped2));
tv_percentage.setText(""+stripped2+"%");
ratingBar1.setRating(Float.parseFloat(stripped2));
编辑后的代码:
float d= (float) (scoring100 /100 * 5);
String S = Double.valueOf(d).toString();
tv2_90.setText(""+S); // for testing only, tv2_90 showing proper value
ratingBar1.setStepSize((d));
ratingBar1.setRating(Float.parseFloat(stripped2));
Layout:
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="100"
android:numStars="5"
android:stepSize="0.1" />
你可以找到它here http://developer.android.com/reference/android/widget/RatingBar.html:
float d= (float) ((number*5) /100);
RatingBar rb = (RatingBar) findViewById(R.id.ratingBar1);
rb.setRating(d);
在你的布局上:
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:max="5"
android:stepSize="0.01" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)