how to get RatingBar value

前端 未结 9 2394
傲寒
傲寒 2021-02-13 18:55

how to read and display rating bar value

i[0] // should be selected value

private OnClickListener onclickbutton1 = new OnClickListener() {
    public void onCli         


        
9条回答
  •  鱼传尺愫
    2021-02-13 19:43

    What you do here is not right: you output the resource id of the rating bar, not its value.

    Let me assume that you have earlier done something like:

    RatingBar mBar = (RatingBar) findViewById(R.id.mRatingBar);
    mBar.setOnClickListener(onclickbutton1);
    

    for example in the activity's onCreate(). Then within the on click listener you provide, you can get the rating as follows:

    public void onClick(View v) {
        RatingBar bar = (RatingBar) v;
        statusMessage.setText("value is " + bar.getRating());
    }
    

提交回复
热议问题