평점 표시 줄을 사용하여 사용자의 점수를 표시하고 싶습니다. 예를 들어, 사용자가 30 개 질문 중 7 개를 맞히면 textview (tv_percentage)는 23.33 %에 대해 올바르게 표시되지만 평점 별은 5 개 중 1.17 개로 표시되어야하지만 지금은 점수가 무엇이든간에, 항상 별 5 개를 표시합니다.
다음에 대해 내가 뭘 잘못 했나요?
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));
<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" />
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" />
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다