Use of seekbar drag progress bar in Android and event listening

Source: Internet
Author: User

Next we will share with you the use of the seekbar drag progress bar in Android and event listening. You need to implement the seekbar. onseekbarchangelistener interface for event listening by dragging the progress bar, and call setonseekbarchangelistener of seekbar to transfer the event listening object to event listening. The event listening interface has three important methods:

1. onstarttrackingtouch Method

This method is called when the progress bar is dragged.

2. onstoptrackingtouch Method

This method is called when the drag progress bar is stopped.

3. onprogresschanged

This method is called when the progress of the drag progress bar changes


We will share with you an example to see the results first:



The instance code is as follows:

Mainactivity. Java

Package com. guu. seekbar;

Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. widget. seekbar;
Import Android. widget. textview;

Public class mainactivity extends activity {
Private seekbar;
Private textview description;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
Seekbar = (seekbar) findviewbyid (R. Id. seekbar );
Description = (textview) findviewbyid (R. Id. Description );
Seekbar. setonseekbarchangelistener (New seekbar. onseekbarchangelistener (){
/**
* Called when the drag bar is stopped
*/
@ Override
Public void onstoptrackingtouch (seekbar ){
Description. settext ("drag to stop ");
}
/**
* Called when a drag entry starts to be dragged
*/
@ Override
Public void onstarttrackingtouch (seekbar ){
Description. settext ("start dragging ");
}
/**
* Called when the drag progress changes
*/
@ Override
Public void onprogresschanged (seekbar, int progress,
Boolean fromuser ){
Description. settext ("current progress:" + progress + "% ");
}
});
}
}


Main. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<Seekbar
Android: Id = "@ + ID/seekbar"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
<Textview
Android: Id = "@ + ID/description"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "drag progress bar"
Android: gravity = "center_horizontal"
/>
</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.