[안드로이드,Android] RatingBar (별점수)

2013. 1. 21. 11:24Mobile/Android



반응형

 

 

MainActivity.java

 

package com.example.rating;

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

public class MainActivity extends Activity {

	RatingBar rating;
	TextView tv01;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		rating = (RatingBar) findViewById(R.id.ratingBar1);
		tv01 = (TextView) findViewById(R.id.tv01);

		rating.setStepSize((float) 0.5); 		//별 색깔이 1칸씩줄어들고 늘어남 0.5로하면 반칸씩 들어감
		rating.setRating((float) 2.5); 		// 처음보여줄때(색깔이 한개도없음) default 값이 0  이다
		rating.setIsIndicator(false);			//true - 별점만 표시 사용자가 변경 불가 , false - 사용자가 변경가능

		rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

			@Override
			public void onRatingChanged(RatingBar ratingBar, float rating,
					boolean fromUser) {
				tv01.setText("평점 : " + rating);

			}
		});

	}

}


        <TEXTVIEW android:layout_height="wrap_content"
                            android:layout_width="wrap_content"
                            android:id="@+id/tv01" /> 

     <RATINGBAR android:layout_height="wrap_content"
                           android:layout_width="wrap_content" 
                           android:id="@+id/ratingBar1" /> 

 </RELATIVELAYOUT> 


반응형