Java/Android - Doesn't add the two values of RatingBar? -
suppose set first value of ratingbar 1 , second value 1,it doesn't add 2.instead shows 1.01.0 .what's wrong here?
ratingbar r1,r2; button submit; r1 = (ratingbar) findviewbyid(r.id.ratingbar1); r2 = (ratingbar) findviewbyid(r.id.ratingbar2); submit = (button) findviewbyid(r.id.submit); submit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { toast.maketext(myactivity.this, string.valueof(r1.getrating())+string.valueof(r2.getrating()), toast.length_short).show(); //shows 1.01.0 } });
it because using +
string objects , int. + operator string has meaning of concatenation. want achievable summing values , converting string. change from
string.valueof(r1.getrating())+string.valueof(r2.getrating())
to
string.valueof(r1.getrating() + r2.getrating())
Comments
Post a Comment