You are on page 1of 13

f/m IMAGE

User name
DATEE TIME ROLLNO
Password

Gender: DISPLAY SELECTED SUBJECT HERE

Male Female 1. Question

a.

Would u like to continue? b.

LOGIN

………

1. Validate user name & password with a regular expression.


2. Testcases that u need to implement here are of :
Username should be of 7 characters & first character would be of caps
(R161XXX).
Password would be of min. 8 characters length & max of 10 characters with
combination alphanumeric & special symbols.

Hint:

. any single character can be matched ,

*: o or more characters ,

+ :1 or more characters ,

? : 0 or more characters ,

[ ] : to choose a character from that specified characters only,


{}-to provide exact length ,

{any number ,}-min length of that number & max can be any number ,

{number , number}-min & max.

3. Display the choosen gender info. in the next activity

Intentobj.putExtra(“key”,value)

4. If checkbox is checked; display the toast msg with all the best, Otherwise
thank u visit once again.

isChecked method & Toast class with makeText() method

5. Redirect to next activity when clicks on login button.

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.

The tag used for this is of : <EditText>

The attribute that we can used along with it are of:

inputType : Through with this attribute u can impose restrictions on to the user by
keyboard layout.

Values that can assign for this attribute are of:

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.

The validation that u can perform on this components are of :

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:

One is onClick attribute in XML & Other one is of OnClickListener( ) method in


Java.

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.

Otherwise one of the option get 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 ();

The three parameters that we need to pass here are of:

1. context: gives info. about the current status of an activity within an


application.
-context can referred through this or getContext ( ) or getApplicationContext
( ) or getBaseContext ( ).

2. Message: the message that u want to display on to the screen.

3. Duration: how much the toast message has to be displayed on the


screen.Two values can be used here: one is LENGTH_LONG & other one is
LENGTH_SHORT.

To display the toast message on to the screen, use show ( ) method.

Toast.makeText (this,” Mobile Application Development”,


Toast.LENGTH_LONG).show( );

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

switch (view.getID()) //view.getID() to get an ID of the component

Case R.id.radiobutton1:

Toast to=Toast.makeText (this,” selected option is”,


Toast.LENGTH_LONG).show( );

to.setGravity (Gravity.TOP|LEFT,10,10); //display msg on top left @ (10,10)

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 ( ).

As an e.g., to know whether checkbox c1 has selected or not.


if (c1.isChecked)
{
Toast.makeText (this,”selected checkbox is”, Toast.LENGTH_LONG).show( );
}

Switch & ToggleButton:

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:

Tag used here is of <Spinner>


To use that, access the ArrayAdapter class through with an object.The parameters
that u need to pass here are of :
1. context: current running activity & application .
2. layout: for spinner use the layout appearance as
android.R.layout.simple_spinner_drop_down_item
3. data stored variable
As an e.g., String[] numbers={“one”,”two”};
a. ArrayAdapter<String> ad=new
ArrayAdapter(this,android.R.layout.simple_spinner_drop_down_item,numb
ers);
It fetches the data from an array & provide the appearance to the data in form of
drop down manner.
b. Provide listener to know which one has selected from drop down list. The
method that u used here is of OnItemSelectedListener( ) with this as
parameter.
-Implement 2 methods by placing cursor & ALT+ENTER.The methods that
need to be implemented here are of OnItemSelected( ) & doNothing( )

OnItemSelected( ) with 4 parameters:


1. Adapter view : specifies the type of view u have used here i.e., spinner
2. View : each item (Textview t=view) //typecast to textview
3. Position :specifies the index value of each item that starts with 0
4. Id :specifies row id of each view

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);

b. Listener : OnItemClickListener( ) with this as a parameter.Provide an


interface for ItemClickListener & implement the method OnItemClick( )
with parameters:
1. Adapter view : specifies the type of view u have used here i.e., spinner
2. View : each item (Textview t=view) //typecast to textview
3. Position :specifies the index value of each item that starts with 0
4. Id :specifies row id of each view

c. To display the spinner on to the activity, use setAdapter( ) method with the
parameter as array adapter object.

DatePickerDialog & TimePickerDialog :


DatePickerDialog & TimePickerDialog are two classes used for:
If u want to get the dialog of calendar then have to use the class DatePickerDialog
& to get the dialog of calendar then have to use the class TimePickerDialog.

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.

You might also like