반응형
<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>
[실행화면]
반응형
'안드로이드' 카테고리의 다른 글
[안드로이드] 여론조사앱 (0) | 2019.10.12 |
---|---|
[안드로이드]이벤트 처리 방법 (0) | 2019.10.07 |
[안드로이드] 사용자 인터페이스 기초 (0) | 2019.10.07 |
[안드로이드] 안드로이드 기초사항 (0) | 2019.10.07 |
[Android] 멀티 터치 (Multi Touch) (0) | 2019.10.07 |
댓글