Complete Demo project code is attached to the seekbar instance of Android.

Source: Internet
Author: User

Complete Demo project code is attached to the seekbar instance of Android.

1. Drag events
Implement the seekbar. onseekbarchangelistener interface. You need to listen to three events:
Onprogresschanged)
Start dragging (onstarttrackingtouch)
Onstoptrackingtouch)

Triggered when onstarttrackingtouch starts to drag. The difference between onprogresschanged and onprogresschanged is that it is triggered only once before stopping the drag.
Onprogresschanged is triggered repeatedly as long as it is being dragged.

2. Main attributes and methods of dragging a bar
Setmax
Set the value of the drag bar
Setprogress
Sets the current value of the drag bar.
Setseconddaryprogress
Sets the value of the second drag, that is, the recommended value of the current drag.

Code:

1 package COM. zdztools. seekbartest; 2 3 Import android. app. activity; 4 Import android. OS. bundle; 5 import android. util. log; 6 Import android. widget. seekbar; 7 Import android. widget. textview; 8 Import android. widget. seekbar. onseekbarchangelistener; 9 10 public class mainactivity extends activity {11 protected static final string tag = "mainactivity"; 12 private seekbar seek; 13 private textview mytextview; 14 15 @ override16 protected void oncreate (bundle savedinstancestate) {17 super. oncreate (savedinstancestate); 18 setcontentview (R. layout. activity_main); 19 20 mytextview = (textview) findviewbyid (R. id. mytextview); 21 seek = (seekbar) findviewbyid (R. id. myseekbar); 22 // initialize 23 seek. setprogress (60); 24 seek. setonseekbarchangelistener (seeklistener); 25 mytextview. settext ("Current Value:-" + 60); 26} 27 28 private onseekbarchangelistener seeklistener = new onseekbarchangelistener () {29 @ override30 public void onstoptrackingtouch (seekbar) {31 log. I (TAG, "onstoptrackingtouch"); 32} 33 34 @ override35 public void onstarttrackingtouch (seekbar) {36 log. I (TAG, "onstarttrackingtouch"); 37} 38 39 @ override40 public void onprogresschanged (seekbar, int progress, 41 Boolean fromuser) {42 log. I (TAG, "onprogresschanged"); 43 mytextview. settext ("Current Value:-" + progress); 44 45} 46 }; 47}
<LinearLayout 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"    android:orientation="vertical"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin" >    <TextView        android:id="@+id/myTextView"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="20dip"        android:text=""        android:textSize="16sp"        android:textStyle="bold" />    <SeekBar        android:id="@+id/mySeekBar"        android:layout_width="fill_parent"        android:layout_height="wrap_content" /></LinearLayout>

Run:

 

Complete Project Instance code: seekbartest.zip

Another blog:Android third-level custom slide switch, click prohibited function implementation, with the default seekbar component implementation

 

Related Article

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.