Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
什么是这个java代码中的TimerSekbar对象或变量?什么是findViewById,_Java_Android_View_Android Seekbar_Findviewbyid - Fatal编程技术网

什么是这个java代码中的TimerSekbar对象或变量?什么是findViewById,

什么是这个java代码中的TimerSekbar对象或变量?什么是findViewById,,java,android,view,android-seekbar,findviewbyid,Java,Android,View,Android Seekbar,Findviewbyid,我检查了findViewById是一个方法,那么什么是timerSeekBar,一个对象或变量,被告知它是一个变量,但我们正在用它调用方法,所以它不应该是一个对象。请解释为什么我们要在findViewById之前编写SeekBar SeekBar -Class,findViewById- Method ?,timerSeekBar- variable or object? SeekBar timerSeekBar = (SeekBar)findViewById(R.id.timerSeekBa

我检查了
findViewById
是一个方法,那么什么是
timerSeekBar
,一个对象或
变量
,被告知它是一个变量,但我们正在用它调用方法,所以它不应该是一个对象。请解释为什么我们要在
findViewById
之前编写
SeekBar

SeekBar -Class,findViewById- Method ?,timerSeekBar- variable or object?

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

timerSeekBar.setMax(600);
timerSeekBar.setProgress(30);
另一例-

TextView answerLabel = (TextView) findViewById(R.id.button1);

方法
findviewbyd
返回实际用于在XML文件中定义该视图的类的实例。 (Seekbar)用于使用特定视图强制转换该视图

您必须将该(
findviewbyd
)强制转换为使用变量时定义的类。 所以,这就是

SeekBar timerSeekBar = (SeekBar)findViewById(R.id.timerSeekBar);
从API 26中,findViewById对其返回类型使用推断,因此您不再需要强制转换

请查看以下参考链接:

ProgressBar是超类,AbsSeekbar是ProgressBar的子类,SeekBar是AbsSeekbar的子类


setMax()是Seekbar的方法,setProgress()是Progressbar的方法。

Seekbar是一个小部件。。它在SeekBar.java文件中定义。本质上,它是android中的
视图。Seekbar最终扩展了基类
View.java
findViewById()
方法用于在android中查找
视图
,使用
setId()
方法为
视图
设置特定id。
我们使用
SeekBar timerSeekBar=(SeekBar)findViewById(R.id.timerSeekBar)
以便告诉系统我们正在使用
findViewById()
方法查找视图,然后将基本
view.class
type对象强制转换为子类
SeekBar.class
type对象
(SeekBar)
用于告诉系统此
视图
SeekBar
的一个实例

谢谢,TimerSekbar是一个对象,对吗?小部件就像一个包裹(请原谅一个noob)?是的。。。请参见,当您基本上编写
TimerSeekBar mySeekBar
时,您将创建名为mySeekBar的类TimerSeekBar的对象。。然后,您可以使用objectName.methodName()访问该类的方法…谢谢,在这个TextView timerTextView=(TextView)findViewById(R.id.timerTextView);TextView也是一个小部件?小部件就像一个包,一组代码就像一组类吗?它是一组代码。。如果按住
ctrl
键并单击TextView,您将找到TextView.java文件的代码。。你会明白的。如果我的解释对你有帮助,请将我的答案标记为已接受。TimerSekBar是变量还是对象?TimerSekBar.setMax(600);和timerSeekBar.setProgress(30);-由变量进行的函数调用。目前我知道只有对象才能进行函数调用。这里findViewById是一个方法,如前所述,在转换为SeekBar类型后分配给变量。因此通常TimerSekbar是一个方法,正在调用其他方法,请说明TimeSeekbar是Seekbar的实例。setMax和setProgress是Seekbar类的方法。Seekbar扩展了具有同步方法setMax()的AbsSeekBar。