Android学习之RatingBar评分组件

main.xml:

 



	
	
	

 

 

MyRatingBarDemo.java:

 

import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;

public class MyRatingBarDemo extends Activity {
	private RatingBar ratingBarA = null; 					// 定义评分组件
	private TextView text = null; 							// 文本显示组件

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.main);
		this.ratingBarA = (RatingBar) super.findViewById(R.id.ratingbarA) ;
		this.text = (TextView) super.findViewById(R.id.text) ;// 取得组件
		this.ratingBarA.setOnRatingBarChangeListener(
				new OnRatingBarChangeListenerImpl());		// 设置监听
	}

	private class OnRatingBarChangeListenerImpl implements
			RatingBar.OnRatingBarChangeListener {
		@Override
		public void onRatingChanged(RatingBar ratingBar, float rating,
				boolean fromUser) {
			MyRatingBarDemo.this.text.append("*** 当前值(Rating):"
					+ ratingBar.getRating() + ",增长步长:"
					+ ratingBar.getStepSize() + "\n"); 		// 增加文本显示
		}
	} 
}

 

 

 

 

 

你可能感兴趣的:(Android基础)