본문 바로가기
안드로이드

[안드로이드] 별 평가(Rating Bar)

by 호아나트 2019. 10. 3.
반응형

 

<MainActivity.java>

package com.example.a5_homework1;
import androidx.appcompat.app.AppCompatActivity;
import android.media.Rating;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final RatingBar ratingbar =(RatingBar)findViewById(R.id.ratingbar);
        ratingbar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener()
        {public void onRatingChanged(RatingBar ratingBar,float rating, boolean fromUser)
        {
            Toast.makeText(MainActivity.this,"New Rating : "+rating,Toast.LENGTH_SHORT).show();
        }
        });
    }
}

<Xml>

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <RatingBar
        android:id="@+id/ratingbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1.0"/>
</LinearLayout>

 

[실행화면]

 

반응형

댓글