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: