Android Ui Controls (Textview, Edittext, Radio Button, Checkbox)
Android Ui Controls (Textview, Edittext, Radio Button, Checkbox)
Following is the pictorial representation of user interface (UI) or input controls in android application.
The View is a base class for all UI components in android and it is used to create an interactive UI
components such as TextView, EditText, Checkbox, Radio Button, etc. and it responsible for event
handling and drawing.
The ViewGroup is a subclass of View and it will act as a base class for layouts and layout parameters.
The ViewGroup will provide an invisible containers to hold other Views or ViewGroups and to define the
layout properties.
To know more about View and ViewGroup in android applications, check this Android View and
ViewGroup.
The android framework will allow us to use either or both of these methods to define our application’s UI.
In android, each input control is having a specific set of events and these events will be raised when the
user performs particular action like, entering the text or touches the button.
Note: we need to create a user interface (UI) layout files in /res/layout project directory, then only the
layout files will compile properly.
If you observe above code we are calling our layout using setContentView method in the form
of R.layout.layout_file_name. Here our xml file name is activity_main.xml so we used file
name activity_main.
Generally, during the launch of our activity, onCreate() callback method will be called by android
framework to get the required layout for an activity.
Create UI Element at Runtime
If we want to create UI elements at runtime, we need to create our own
custom View and ViewGroupobjects programmatically with required layouts.
Following is the example of creating an UI elements (TextView, EditText, Button) in LinearLayout using
custom View and ViewGroup objects in an activityprogrammatically.
Following is the example of setting width and height for View and ViewGroup elements in XML layout
file.
match_parent
wrap_content
If we set value match_parent, then the View or ViewGroup will try to match with parent width or
height.
If we set value wrap_content, then the View or ViewGroup will try to adjust its width or height based
on the content.
TextView
EditText
AutoCompleteTextView
Button
ImageButton
ToggleButton
CheckBox
RadioButton
RadioGroup
ProgressBar
Spinner
TimePicker
DatePicker
SeekBar
AlertDialog
Switch
RatingBar
Android TextView
In android, TextView is a user interface control which is used to display the text to the user.
To know more about TextView control check this, Android TextView with Examples.
Android EditText
In android, EditText is a user interface control which is used to allow the user to enter or modify the text.
To know more about EditText, check this Android EditText with Examples.
Android AutoCompleteTextView
In android, AutoCompleteTextView is an editable text view which is used to show the list of
suggestions based on the user typing text. The list of suggestions will be shown as a dropdown menu
from which the user can choose an item to replace the content of textbox.
To know more about AutoCompleteTextView, check this Android AutoCompleteTextView with Examples.
Android Button
In android, Button is a user interface control which is used to perform an action when the user click or
tap on it.
To know more about Button in android check this, Android Buttons with Examples.
To know more about Image Button in android check this, Android Image Button with Examples.
Android CheckBox
In android, Checkbox is a two states button that can be either checked or unchecked.
To know more about CheckBox in android check this, Android CheckBox with Examples.
To know more about Radio Button in android check this, Android Radio Button with Examples.
Android Radio Group
In android, Radio Group is used to group one or more radio buttons into separate groups based on our
requirements.
In case if we group radio buttons using radio group, at a time only one item can be selected from the
group of radio buttons.
To know more about Radio Group in android check this, Android Radio Group with Examples.
Android ProgressBar
In android, ProgressBar is a user interface control which is used to indicate the progress of an operation.
To know more about ProgressBar, check this Android ProgressBar with Examples.
Android Spinner
In android, Spinner is a drop-down list which allows a user to select one value from the list.
To know more about Spinner, check this Android Spinner with Examples.
Android TimePicker
In android, TimePicker is a widget for selecting the time of day, either in 24-hour or AM/PM mode.
To know more about TimePicker, check this, Android TimePicker with Examples.
Android DatePicker
In android, DatePicker is a widget for selecting a date.
To know more about DatePicker, check this Android DatePicker with Examples.