我正在学习Android编程,我在活动类(而不是xml)中创建命令按钮的方式是"import android.widget.Button;"
,然后创建Button实例,例如"Button exit = (Button) findViewById(R.id.exitButton);"
但是我遇到了一些源代码文件,其中包含一个用作按钮的View实例。其余代码似乎相似,但唯一的区别是他使用的是View类而不是Button类。
有人可以告诉我这两种方法之间的区别吗?
提前致谢!
答案 0 :(得分:0)
以下代码均有效:
Button exit = (Button) findViewById(R.id.exitButton);
View exit = (Button) findViewById(R.id.exitButton);
因为查看是所有小部件的 super class
,例如Button,ListView,GridView,RelativeLayout,LinearLayout等。