(Turkish) Türk Telekom, Açık Şebeke Otomasyon Platformu (ONAP)’na üye oldu

(Turkish) SanalUzman.com’dan serbest çalışanlara (freelancer) 10 öneri

(Turkish) WordPress Temada Kategorileri Listeleme

Hal

Android RatingBar Example

  • Android Programming
  • Savaş Dersim Çelik
  • Sunday June 18th, 2017
  • 880 Görüntülenme
  • JAVA
  • Mobile

Android RatingBar can be used to get the rating from the user. The Rating returns a floating-point number. It may be 2.0, 3.5, 4.0 etc.

Android RatingBar displays the rating in stars. Android RatingBar is the subclass of AbsSeekBar class.

The getRating() method of android RatingBar class returns the rating number.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >


    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="18dp" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="121dp"
        android:textSize="25dp"
        android:text="Webinyo.COM"
        android:layout_below="@+id/ratingBar"
        android:layout_centerHorizontal="true" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ratingBar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="41dp"
        android:text="GÖNDER" />

</RelativeLayout>
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.Toast;

public class MainActivity extends Activity {
    RatingBar ratingbar1;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        addListenerOnButtonClick();
    }

    public void addListenerOnButtonClick(){
        ratingbar1=(RatingBar)findViewById(R.id.ratingBar);
        button=(Button)findViewById(R.id.button2);
        //Performing action on Button Click
        button.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                //Getting the rating and displaying it on the toast
                String rating=String.valueOf(ratingbar1.getRating());
                Toast.makeText(getApplicationContext(), rating, Toast.LENGTH_LONG).show();
            }

        });
    }
}

Yorumlar

Henüz hiç yorum yapılmamış.

Benzer İçerikler