B
B
brucebanner2016-06-14 21:26:28
Java
brucebanner, 2016-06-14 21:26:28

Three lines that need an explanation!?

Trying to understand this code
1- In the layout, id.seek is SeekBar, and the type is specified as ProgressBar
2- `mProgress instanceof SeekBar` . Here ( javapd.blogspot.com/2008/05/25-8.html) it says

The instanceof operator checks whether the class of the left operand matches the name of the class given by the right operand or is a subclass of it.

those. whether the class `mProgress'a` is the same as the class `SeekBar` or whether `mProgress` is a subclass of `SeekBar'a` .
Did I understand correctly? If correct, then `SeekBar` is inherited from `ProgressBar` , so `instanceOf` will return `false`. But the program works, so I did not understand.
And what exactly is `mProgress` , `ProgressBar` or `SeekBar` (according to the markup).
3 - I don't understand this at all.
private ProgressBar mProgress;
    ...
    // 1.тип указывается  ProgressBar, а привязывается к SeekBar???
        mProgress = (ProgressBar) v.findViewById(R.id.seek);
        if (mProgress != null){
            // 2....
            if (mProgress instanceof SeekBar){
                // 3....
                SeekBar seeker = (SeekBar) mProgress;
                seeker.setOnSeekBarChangeListener(seekListener);
            }
            mProgress.setMax(1000);
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2016-06-14
@brucebanner

R.id.seek can contain anything inherited from ProgressBar,
even though MySuperPerfectProgressBar, but if
if (mProgress instanceof SeekBar)
mProgress contains SeekBar or a subclass from it,
then fulfill the condition

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question