Android評分條示例含代碼

    Android評分條示例

    Android RatingBar 可以用來獲取用戶的評分。愛掏網 - it200.com評分返回一個浮點數,例如2.0,3.5,4.0等。愛掏網 - it200.com

    Android RatingBar會以星星的形式顯示評分。愛掏網 - it200.comAndroid RatingBar是AbsSeekBar類的子類。愛掏網 - it200.com

    android RatingBar類的 getRating() 方法會返回評分數字。愛掏網 - it200.com

    讓我們看一個簡單的Android評分條示例。愛掏網 - it200.com

    activity_main.xml

    從工具箱中拖動RatingBar和Button,現在activity_main.xml文件將如下所示:

    <?xml version="1.0" encoding="utf-8"?>  
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        xmlns:app="http://schemas.android.com/apk/res-auto"  
        xmlns:tools="http://schemas.android.com/tools"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        tools:context="example.javatpoint.com.ratingbar.MainActivity">  
    
        <Button  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="submit"  
            android:id="@+id/button"  
            app:layout_constraintBottom_toBottomOf="parent"  
            app:layout_constraintLeft_toLeftOf="parent"  
            app:layout_constraintRight_toRightOf="parent"  
            app:layout_constraintTop_toTopOf="parent"  
            app:layout_constraintVertical_bias="0.615" />  
    
        <RatingBar  
            android:id="@+id/ratingBar"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:layout_marginLeft="72dp"  
            android:layout_marginTop="60dp"  
            app:layout_constraintStart_toStartOf="parent"  
            app:layout_constraintTop_toTopOf="parent" />  
    
    </android.support.constraint.ConstraintLayout>  
    

    Activity類

    讓我們來編寫代碼以顯示用戶的評分。愛掏網 - it200.com

    package example.javatpoint.com.ratingbar;
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.RatingBar;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
        RatingBar ratingbar;
        Button button;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            addListenerOnButtonClick();
        }
        public void addListenerOnButtonClick(){
            ratingbar=(RatingBar)findViewById(R.id.ratingBar);
            button=(Button)findViewById(R.id.button);
            //Performing action on Button Click
            button.setOnClickListener(new View.OnClickListener(){
    
                @Override
                public void onClick(View arg0) {
                    //Getting the rating and displaying it on the toast
                    String rating=String.valueOf(ratingbar.getRating());
                    Toast.makeText(getApplicationContext(), rating, Toast.LENGTH_LONG).show();
                }
    
            });
        }
    }
    

    輸出:

    聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
    發表評論
    更多 網友評論0 條評論)
    暫無評論

    返回頂部

    主站蜘蛛池模板: 精品福利视频一区二区三区| 国产在线视频一区| 精品国产一区二区三区久久狼| 国产福利电影一区二区三区久久老子无码午夜伦不 | 亚洲午夜在线一区| 国产一区二区在线视频播放| 国产成人精品久久一区二区三区| 久久影院亚洲一区| 精品国产一区二区三区www| 久久久无码精品国产一区| 中文字幕一区二区日产乱码| 国产在线一区视频| 另类ts人妖一区二区三区| 亚洲愉拍一区二区三区| 亚洲va乱码一区二区三区| 无码少妇一区二区三区浪潮AV| 中文字幕无码一区二区三区本日| 一区二区中文字幕在线观看| 国产女人乱人伦精品一区二区| 性色av闺蜜一区二区三区| 日本一区二区三区免费高清| 国产一区二区不卡老阿姨| 中文字幕日韩一区二区不卡| 无码播放一区二区三区| 国产吧一区在线视频| 一区二区三区在线观看| 日本国产一区二区三区在线观看 | 成人精品一区二区三区不卡免费看 | 成人精品一区久久久久| 日韩成人一区ftp在线播放| 风间由美在线亚洲一区| 国产日韩精品一区二区在线观看播放| 国产精品视频一区国模私拍| 国产天堂在线一区二区三区| 人妻内射一区二区在线视频| 人妻少妇一区二区三区| 日韩人妻一区二区三区免费 | 国产成人一区二区动漫精品| 无码人妻一区二区三区精品视频| 国产日韩AV免费无码一区二区三区| 国产一区二区三区夜色|