buttonBlue = (Button) findViewById(R.id.buttonInvisibleMan) 中“(Button)”的重要性;

Importance of "(Button)" in buttonBlue = (Button) findViewById(R.id.buttonInvisibleMan);

我在做this course on Coursera, and in the 3rd week 1st block video,老师让我们写了下面一行代码:

buttonBlue = (Button) findViewById(R.id.buttonInvisibleMan);

这行代码各部分的意义是什么? R.id 是什么意思?代表? “(按钮)”的重要性是什么?

请详细解释每一部分。

谢谢

R.id。代表资源 ID,这很重要,因为 blueButton 需要知道它需要使用哪个 UI 元素。

(Button) 是一种转换形式,通过编写 (Button) 您向编译器保证这将是一个 Button 元素,而不是 TextView 或任何其他 UI 元素。