About Android Development implementation drag bars and star reviews

Source: Internet
Author: User

Drag bar Assembly (SeekBar)

<SeekBar Android:id="@+id/seekbar1"Android:layout_width="match_parent"Android:layout_height="wrap_content"Android:max=" -"      //set the maximum valueandroid:progress="0"   //Set initial valueandroid:padding="10px"/>


Star rating Strips (Ratingbar)

<Ratingbar Android:id="@+id/ratingbar1"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:numstars="5" //set several starsandroid:rating="3.5"    //set the initial star ratingAndroid:isindicator="false"  //setting allows users to change star rating/>


Full code

Layout

<?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"> <TextView Android:id="@+id/now_num"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:text="Current value: 0"android:textappearance="? Android:attr/textappearancelarge"/> <SeekBar Android:id="@+id/seekbar1"Android:layout_width="match_parent"Android:layout_height="wrap_content"Android:max=" -"android:progress="0"android:padding="10px"/> <Ratingbar Android:id="@+id/ratingbar1"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:numstars="5"android:rating="3.5"Android:isindicator="false"/> <Button Android:id="@+id/button_star"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:text="Ratings"/></linearlayout>

Java files

1 Package Lianxi;2 3 import Com.example.jichu_lianxi. R;4 5 import android.app.Activity;6 import Android.os.Bundle;7 import Android.util.Log;8 import Android.view.View;9 import Android.view.View.OnClickListener;Ten import Android.widget.Button; One import Android.widget.RatingBar; A import Android.widget.SeekBar; - import Android.widget.SeekBar.OnSeekBarChangeListener; - import Android.widget.TextView; the import Android.widget.Toast; -  -  Public classSeekbar_or_ratingbar extends activity{ -     PrivateSeekBar SeekBar;//Drag Bar +     PrivateTextView text;//text box showing the current value of the drag bar -     PrivateButton Button_star;//Scoring Buttons +     PrivateRatingbar Ratingbar; A @Override at     protected voidonCreate (Bundle savedinstancestate) { -         //TODO auto-generated Method Stub - super.oncreate (savedinstancestate); - Setcontentview (r.layout.seekbar_or_ratingbar); -          -Seekbar =(SeekBar) Findviewbyid (R.ID.SEEKBAR1); inText =(TextView) Findviewbyid (r.id.now_num); -Button_star =(Button) Findviewbyid (R.id.button_star); toRatingbar =(Ratingbar) Findviewbyid (R.ID.RATINGBAR1); +         //The response event of the drag bar -Seekbar.setonseekbarchangelistener (NewOnseekbarchangelistener () { the              *             //response event at end of drag $ @OverridePanax Notoginseng              Public voidOnstoptrackingtouch (SeekBar SeekBar) { -                 //TODO auto-generated Method Stub theToast.maketext (Seekbar_or_ratingbar. This,"End Slide", Toast.length_short). Show (); +                  A             } the             //response event when starting to drag + @Override -              Public voidOnstarttrackingtouch (SeekBar SeekBar) { $                 //TODO auto-generated Method Stub $Toast.maketext (Seekbar_or_ratingbar. This,"Start Sliding", Toast.length_short). Show (); -             } -             //responding to events during drag the @Override -              Public voidOnprogresschanged (SeekBar SeekBar,intProgress, Boolean Fromuser) {Wuyi                 //TODO auto-generated Method Stub theText.settext ("Current Value:"+progress);  -             } Wu         }); -         //response events for the scoring button AboutButton_star.setonclicklistener (NewOnclicklistener () { $              - @Override -              Public voidOnClick (View v) { -                 //TODO auto-generated Method Stub A                 intresult = Ratingbar.getprogress ();//Get Progress +                 floatRating = Ratingbar.getrating ();//Get Rank the                 floatStep = Ratingbar.getstepsize ();//get the minimum number of stars to change at a time -Toast.maketext (Seekbar_or_ratingbar. This,"you got it."+rating+"Star", Toast.length_short). Show (); $                  the                  the             } the         }); the     } -  in}

About Android Development implementation drag bars and star reviews

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.