Seekbar for Android Study Notes

Source: Internet
Author: User

<1> Introduction

Seekbar is similar to progressbar, but the main function of progressbar is to let the user know the current status, and seekbar is to let the user adjust the progress. For example, in a music player, you can use seekbar to adjust the progress of music playback.
Seekbar is an extension of progressbar. What is the difference from the original progress bar? There is no slider on the original progress bar. So seekbar can slide back and forth. I believe that such progress bars are not unfamiliar to everyone.

Video players and music players. Fast forward, fast return, and arrival at the specified location are all implemented in this way.

Call the setmax () method to set the maximum value.

Call setprogress () to set the progress value.

Listener:
Call the setonseekbarchangelistener () method to append a value change event.

private class ChangedListener implements SeekBar.OnSeekBarChangeListener{public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stub}public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}        }

The above code is the seekbar listener. Seekbar. onseekbarchangelistener shows that onseekbarchangelistener is the internal interface of seekbar.
To implement this listener, you must implement three methods.

Method 1: This method is called when you drag the slider.

This method is called whenever the slider changes.

Boolean fromuser is used to determine whether it is a manual slide. Int progress indicates the position to which the change is made;

Method 2: This method is called when you start to drag the slider.

Method 3: This method is called when you stop dragging the slider.

<2> example:

Package xiaosi. seekbar; import android. app. activity; import android. OS. bundle; import android. widget. seekbar; public class seekbaractivity extends activity {/** called when the activity is first created. */private seekbar = NULL; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); seekbar = (seekbar) findviewbyid (R. id. seekbar); seekbar. setmax (100); seekbar. setonseekbarchangelistener (New changedlistener ();} private class changedlistener implements seekbar. onseekbarchangelistener {public void onprogresschanged (seekbar, int progress, Boolean fromuser) {system. out. println ("slide" + progress);} public void onstarttrackingtouch (seekbar) {system. out. println ("START");} public void onstoptrackingtouch (seekbar) {system. out. println ("stop ");}}}

 

Main. xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="SeekBar"        android:gravity="center" />    <SeekBar         android:id="@+id/seekbar"        android:layout_width="fill_parent"        android:layout_height="wrap_content"/></LinearLayout>

 

 

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.