Showing posts with label SeekBar. Show all posts
Showing posts with label SeekBar. Show all posts

SeekBar.setProgress()

SeekBar.setProgress() was added in API Level 1
Set the current progress to the specified value. Does not do anything if the progress bar is in indeterminate mode. Parameters: progress the new progress, between 0 and getMax()

1. Find a SeekBar using ID

2. Declare and Initialize an integer named intCurrentPosition, set to 1000.

3. Seekbar.setMax

4. In the MainActivity.java file, add the following to the onCreate method.

 mySeekBar.setProgress(intCurrentPosition);

5. Compile and run!

Resources:
http://developer.android.com/reference/android/widget/ProgressBar.html#setProgress(int)
http://united-coders.com/nico-heid/an-android-seekbar-for-your-mediaplayer/
http://stackoverflow.com/questions/16163431/android-mediaplayer-audio-seekbar


Find a SeekBar using ID

How to Find a SeekBar using ID

findViewById was in API Level 1
findViewById: Look for a child Button with the given id. If this view has a given id, return this SeekBar.

1. Name the SeekBar, mySeekBar.

2. In the MainActivity.java file, add the SeekBar import to the imports section.

     import android.widget.SeekBar;

3. In MainActivity, java file, add the below code to the onCreate method. Where R.id.mySeekBar is the same as the android:id name in your main.xml file, and mySeekBar is the SeekBar name referred to in Java.

SeekBar mySeekBar = (SeekBar) findViewById(R.id.mySeekBar); 

4. Compile and run!

Related Articles:

Resources:

android:id - Name a SeekBar

How to Name a SeekBar

android:id was added in API Level 1
This is an unique identifier name for a SeekBar, so you can refer to the SeekBar later in your project.

1. Add a SeekBar in your main.xml file.

2. In the main.xml file, add the code below.

  <SeekBar
        ...
       android:id = "@+id/mySeekBar"
  />

3. The "+" character is required if you have not yet defined that id, if perhaps the element you reference is lower in the .xml file.

Otherwise you if it's already defined above (or included) then you can omit the "+" char:

4. Compile and run!

Next Recommended Article: Find a SeekBar using ID

Related Articles:

Resources:
http://developer.android.com/reference/android/view/View.html#attr_android:id
http://developer.android.com/reference/android/R.attr.html#id
http://android-wtf.com/2012/11/difference-between-at-plus-id-and-at-id-in-android/
http://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android
http://stackoverflow.com/questions/5048586/can-you-set-tab-order-in-xml-layout
http://stackoverflow.com/questions/16163431/android-mediaplayer-audio-seekbar


How to Add a SeekBar, in XML

How to Add a SeekBar, in XML

SeekBar was added in API Level 1
A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.
The default SeekBar is a wide bar.

1. Create an Android project, if you don't already have one.

2. In the main.xml file, add the below code after your layout tags.

<SeekBar
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
/>

3. Compile and run!

Next Recommended Article: Name a SeekBar

Related Articles:

Resources:
http://developer.android.com/reference/android/widget/SeekBar.html
www.androidhive.info/2012/03/android-building-audio-player-tutorial/