Professional Documents
Culture Documents
User Input Controls
User Input Controls
User name
DATEE TIME ROLLNO
Password
a.
LOGIN
………
Hint:
*: o or more characters ,
+ :1 or more characters ,
? : 0 or more characters ,
{any number ,}-min length of that number & max can be any number ,
Intentobj.putExtra(“key”,value)
4. If checkbox is checked; display the toast msg with all the best, Otherwise
thank u visit once again.
Intent Class with 2 parameters (present working activity , to whom the activity is communicating)
6. Within second activity display the rollno from first activity that u have
entered in username edit text.
7. Provide list of subjects as drop-down with the spinner.
8. The subject that has selected displayed on the text view.
Textviewobj.setText(variable)
EditText:
It is one of the user input control, through which we can provide the info . and can
edit it.
inputType : Through with this attribute u can impose restrictions on to the user by
keyboard layout.
text (layout with alphanumerics) , number (layout with numbers) , textUri ( layout
with / symbol)…..,
hint : for providing info. to user about wat to enter into that edittext.
1. Whether edit text is empty or not through with the method: isEmpty ( )
2. The username should contain only alphabets , it can be validated using
Regular Expression.
- Regular Expression that provides a pattern to the string.
- To check the text that entered in edit text matched with regular
expression use the class Pattern with the method matches( ) &
parameters are of regular expression & text to be matched with or text
stored variable.
Pattern.matches (regular expression is of” [a-za-z]*”,et); //et –text stored
variable
A Listener Method can be defined in 2 ways:
RadioButton:
Out of multiple options only one option get selected at a time through with the help
of RadioButton.
To make sure to have to select only one out of all, place all radio buttons within
RadioGroup.
The listener method that u used to provide listener for checkbox to do perform
some action when we Checked or unchecked it is of
SetOnClickListener ( )
The parameter that u need to pass for above method is of current running activity.It
can be referred through with this.
SetOnClickListener (this);
There u got an error place the cursor on this & enter ALT+ENTER.Provide an
interface for onViewClickListener & a dialog box opens with the method
onClick( ).
Choose that one & implement the code for wat should have to do when user
checked or unchecked the checkbox.
or else simply use the onClick attribute in XML for click listener.
To know whether any one among radiobutton has been choosen or not use the
method
GetRadioButtonCheckedId ( ), if it returns -1 then none of the option has been
selected.
To know which one has been selected, Use switch to know which one has selected
& Toast class to display the info. about the selected option with makeText ( )
method.
Toast.makeText ();
To place the Toast message on specified position use the method setGravity from
Toast class.
Toastobject.setGravity( );
The three parameters need to pass for this method are of position (top , down , left ,
right):Gravity.TOP , x-offset & y-offset
The case labels would be of ID of each radio button component. As an e.g., if the
radio button has an ID of R.id.radiobutton1
Case R.id.radiobutton1:
CheckBox:
The listener method that u used to provide listener for checkbox to do perform
some action when we Checked or unchecked it is of
SetOnClickListener ( )
The parameter that u need to pass for above method is of current running activity.It
can be referred through with this .
SetOnClickListener (this);
There u got an error place the cursor on this & enter ALT+ENTER.Provide an
interface for onViewClickListener & a dialog box opens with the method onClick(
).
Choose that one & implement the code for wat should have to do when user
checked or unchecked the checkbox.
Or else simply use the onClick attribute in XML for click listener.
To know whether checkbox has checked or unchecked through with the method
isChecked ( ).
ON OFF
Through with these components we can place the button in either ON mode or
OFF.
The tag used for switch component is of <Switch> & for togglebutton it is of
<ToggleButton>
The attributes that u can used along with these components are of:
text: to know for wat purpose u r using the switch or toggle button.
textOn: the action to perform when switch is enabled to ON.
TextOff: the action to perform when switch is enabled to OFF.
The listener method used to know which action has to be performed when switch
is either On or Off.
setOnCheckedChangeListener ( )
Pass the parameter as this: setOnCheckedChangeListener (this);
Provide an interface for viewOnClickListener & implement the method
OnCheckedChanged ( )
To know whether switch is enabled or not, use isChecked ( ).
The data that has been stored in array or in database can be organized as:
In vertical (Listview) , in horizontal (Gallery ){from 4.1 it gets deprecated} , in
rows & columns (Gridview) & drop-down (Spinner).
To implement any one the above need to access the Adapter class.
ADAPTER:
It loads the data partially that has been fetched from data sources.3 types of
adapter,they are of:
1. ArrayAdapter : if u r fetching the data from an array.
2. SimpleCursorAdapter : if u r fetching the data from the database.
3. BaseAdapter :if u r providing ur own layout along with the data
Adapter fetches the data from data source and create a view for each data item
within that data source.(The view is of textview here by default.)
Finally adapterview provide some appearance for the fetched data.
Spinner:
c. To display the spinner on to the activity, use setAdapter( ) method with the
parameter as array adapater object.
ListView:
Displays the data vertically that has been fetched from array.So here we need to
access the ArrayAdapter class.
Tag: <ListView>
To get access of listview use arrayadapter class:
a. ArrayAdapter<String> ad=new
ArrayAdapter(this,android.R.layout.simple_list_item,numbers);
c. To display the spinner on to the activity, use setAdapter( ) method with the
parameter as array adapter object.
DatePickerDialog:
DatePickerDialog dpd=new DatePickerDialog( ) ;
The parameters that u need to pass here are of :
1. Context : current running activity within an application can be defined by
this.
2. Listener method : DatePickerDialog.OnDateSetItem( ) can be referred by
this.
3. Year
4. Month
5. Day
To get year , month , day we need to access the Calendar class with its
object.
Calendar c= Calendar.getInstance( ) ;
Year=c.get(Calendar.YEAR) , Month=c.get(Calendar.MONTH) ,
Day=c.get(Calendar.DAYOFMONTH)
DatePickerDialog dpd=new DatePickerDialog (this ,this, c.get(Calendar.YEAR),
c.get(Calendar.MONTH), c.get(Calendar.DAYOFMONTH));
-gives the dialog of calendar with year ,month & day.
dpd.show( );
to show that dialog on to screen use show( ) method.
Implement the method OnDateSet( ) with parameters :
1. View
2. Year
3. Month
4. Day
This method gives the selected day of month with the year .
TimePickerDialog:
TimePickerDialog tpd=new DatePickerDialog( ) ;
The parameters that u need to pass here are of :
6. Context : current running activity within an application can be defined by
this.
7. Listener method : TimePickerDialog.OnTimeSetItem( ) can be referred by
this.
8. hour
9. Minute
10.Boolean value(true/false)
To get hour, minute we need to access the Calendar class with its object.
Calendar c= Calendar.getInstance( ) ;
hour=c.get(Calendar.HOUROFDAY) , Minute=c.get(Calendar.MINUTE)
TimePickerDialog dpd=new TimePickerDialog (this ,this,
c.get(Calendar.HOUROFDAY), c.get(Calendar.MINUTE), false/true);
-gives the dialog of clock with hour & minute.
tpd.show( );
to show that dialog on to screen use show( ) method.
Implement the method OnTimeSet( ) with parameters :
5. View
6. hour
7. minute
8. boolean
This method gives the selected hour with minutes.