I’m currently learning Android programming and the way I used to create command buttons in the activity class (not xml) is to "import android.widget.Button;" and then to create the Button instance such as "Button exit = (Button) findViewById(R.id.exitButton);"
But I have came across some source code file that contains a View instance that is being used as a button. The rest of the code seems to be similar but the only difference is that he is using View class instead of Button class.
Can someone please tell me the difference between these two methods?
Thanks in advance!
Both the below code are valid:
Button exit = (Button) findViewById(R.id.exitButton);View exit = (Button) findViewById(R.id.exitButton);Because View is the
super classof all the widgets like Button, ListView, GridView, RelativeLayout, LinearLayout etc.Look at this snap for Button class:
Now, check the below snap for RelativeLayout: