如何获得的RatingBar值 [英] how to get RatingBar value
本文介绍了如何获得的RatingBar值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何阅读和显示等级栏值
I [0] //应选择值
私人OnClickListener onclickbutton1 =新OnClickListener(){
公共无效的onClick(视图v){
INT [1 =新的INT [] {R.id.mRatingBar};
statusMessage.setText(值是+ I [0]);
}
};
//这个作品
私人OnClickListener onclickbutton1 =新OnClickListener(){
公共无效的onClick(视图v){
的RatingBar毫巴=(的RatingBar)findViewById(R.id.mRatingBar);
浮[1 =新的浮动[] {mBar.getRating()};
statusMessage.setText(值。+ I [0]);
}
};
解决方案
什么你在这里做是不对的。你输出的评级杆的资源ID,而不是它的价值
让我假设你已经做得比较早是这样的:
的RatingBar毫巴=(的RatingBar)findViewById(R.id.mRatingBar);
mBar.setOnClickListener(onclickbutton1);
例如,在活动的的onCreate()
。然后在点击侦听器内提供,你可以得到的评级如下:
公共无效的onClick(视图v){
的RatingBar栏=(的RatingBar)V;
statusMessage.setText(值是+ bar.getRating());
}
how to read and display rating bar value
i[0] // should be selected value
private OnClickListener onclickbutton1 = new OnClickListener() {
public void onClick(View v) {
int[] i = new int[]{ R.id.mRatingBar};
statusMessage.setText("value is " + i[0]);
}
};
// this works
private OnClickListener onclickbutton1 = new OnClickListener() {
public void onClick(View v) {
RatingBar mBar = (RatingBar) findViewById(R.id.mRatingBar);
float[] i = new float[]{ mBar.getRating() };
statusMessage.setText("value is.. " + i[0]);
}
};
解决方案
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());
}
这篇关于如何获得的RatingBar值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文