I checked findViewById
is a method so what is timerSeekBar
, an object or a variable
,got told its a variable but we are calling methods with it so it should'nt it be an object.Please explain why are we writing SeekBar
before findViewById
.
SeekBar -Class,findViewById- Method ?,timerSeekBar- variable or object?
SeekBar timerSeekBar = (SeekBar)findViewById(R.id.timerSeekBar);
timerSeekBar.setMax(600);
timerSeekBar.setProgress(30);
another eg-
TextView answerLabel = (TextView) findViewById(R.id.button1);
The method findViewById
returns an instance of the class that is actually used to define that view in your XML file.
(Seekbar) is used to cast that view with specific view.
You have to cast that(findViewById
) to the class that your variable is defined when you use it.
So, This is the reason for
SeekBar timerSeekBar = (SeekBar)findViewById(R.id.timerSeekBar);
From API 26, findViewById uses inference for its return type, so you no longer have to cast.
Please check below reference link : https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/SeekBar.java
ProgressBar is super class, AbsSeekbar is Child class of Progressbar and SeekBar is childclass of AbsSeekbar.
setMax() is method of Seekbar and setProgress() is method of Progressbar.