Quantcast
Channel: RatingBar – TechBooster
Viewing all articles
Browse latest Browse all 4

レイティングバーを使う

$
0
0

レイティングバーとは下の写真のように、レートを星の点灯で表すためのビューです。

用途としてはなにかの評価を行うような場合に使います。

というわけで今回はレイティングバーの使い方についてご紹介します。
詳細はつづきからどうぞ。

レイティングバーの定義

まずはレイアウトファイルにレイティングバーを定義しましょう。
以下のようなコードをレイアウトファイルに追記します。

<RatingBar
    android:id="@+id/ratingbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

このとき指定できる属性は主に以下のようなものがあります。

numStar 最大レート値
rating デフォルトのレート値
stepSize レートのステップサイズ値

上の例では最大レートを3に、デフォルトのレートを2.5にしています。

レートが変更されたことを知るには

レートが変更されたことはOnRatingBarChangeListenerを使って知ることができます。
たとえばレートが変更されたときにToastでレートの値を表示するには以下のようにします。

public class RatingBarSample extends Activity implements RatingBar.OnRatingBarChangeListener {
    /** Called when the activity is first created. */
    RatingBar RatingBar;
    Toast mToast;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        RatingBar = (RatingBar) findViewById(R.id.ratingbar);
        RatingBar.setOnRatingBarChangeListener(this);
    }

    public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
        if (mToast != null) {
            mToast.cancel();
        }
        mToast = Toast.makeText(RatingBarSample.this, "Current Rating is "+RatingBar.getRating(), Toast.LENGTH_LONG);
        mToast.show();
    }
}


Viewing all articles
Browse latest Browse all 4

Trending Articles


Vimeo 10.7.0 by Vimeo.com, Inc.


FORTUITOUS EVENT


Pokemon para colorear


Sapos para colorear


Inspirational Quotes For you and Motivates you


Inggit Quotes and Taray Quotes


Re:Mutton Pies (lleechef)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.1 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Knock knock jokes


RE: Mutton Pies (frankie241)


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Vimeo 11.5.1 by Vimeo.com, Inc.


Vimeo 11.8.1 by Vimeo.com, Inc.