İçeriğe geç

Android Rating Bar ile Video Derecelendirme Örnek

Button’a tıklandığında rating bar ile video için belirlediğimiz ratingi ekranda göstermek.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ratingbar.MainActivity"
android:orientation="vertical">

<RatingBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ratingBar"
android:layout_weight="1"
android:numStars="5"
android:rating="0"
android:stepSize="1"
android:isIndicator="true" />

<TextView
android:text="Rating :"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_weight="1" />

<Button
android:text="SUBMIT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonSubmit"
android:layout_weight="1" />

<VideoView
android:layout_width="match_parent"
android:id="@+id/YouTubeVideoView"
android:layout_weight="4.45"
android:layout_height="150dp" />

</LinearLayout>
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);
final TextView textView = (TextView) findViewById(R.id.textView);
final Button button = (Button) findViewById(R.id.buttonSubmit);

VideoView v=(VideoView) findViewById(R.id.YouTubeVideoView);
v.setMediaController(new MediaController(this));
v.setVideoPath("android.resources://" + getPackageName() + "/" + R.raw.aaa);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText(String.valueOf(ratingBar.getRating()));
}
});

ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
Toast.makeText(MainActivity.this,String.valueOf(ratingBar.getRating()),Toast.LENGTH_SHORT).show();
}
});
}
}
ratingbar-example
Kategori:Android

İlk Yorumu Siz Yapın

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir