You are on page 1of 13

SESSION-2

1. Write note on Picker and List Views in Android


Android ListView is a view which groups several items and display them in vertical
scrollable list. The list items are automatically inserted to the list using an Adapter that
pulls content from a source such as an array or database.
The ListView is a subclasses of AdapterView and they can be populated by binding them
to an Adapter, which retrieves data from an external source and creates a View that
represents each data entry.
Listview Attributes:-

Picker:-
Android DatePicker is a user interface control that is used to select the date by day,
month, and year in the android application. DatePicker is used to ensure that the users
will select a valid date. In android DatePicker having two modes, the first one shows
the complete calendar and the second one shows the dates in the spinner view. One can
create a DatePicker control in two ways either manually in the XML file or create it in
the Activity file programmatically .

Methods:-
3. Explain Fragments and Intents with an Android Application Program.
Fragments:-
Android Fragment is the part of activity, it is also known as sub-activity. There can be
more than one fragment in an activity. Fragments represent multiple screen inside one
activity. Android fragment lifecycle is affected by activity lifecycle because fragments are
included in activity. Each fragment has its own life cycle methods that is affected by
activity life cycle because fragments are embedded in activity. The FragmentManager
class is responsible to make interaction between fragment objects
Eg:- public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Fragment:-
public class Fragment1 extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}
Intent:-
An intent is to perform an action on the screen. It is mostly used to start activity, send
broadcast receiver, start services and send message between two activities. There are two
intents available in android as Implicit Intents and Explicit Intents.
Eg:-
Activity-1:-
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
Button send = findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent send = new Intent(MainActivity.this, SecondActivity.class);
startActivity(send);
}
});
}
}
Secound Activity:-
public class SecondActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
TextView data=findViewById(R.id.data);
data.setText("This is second activity");
}
}
4. Explain the Various Layouts, Controls and Views in Android
Layouts:-
Android Layout is used to define the user interface that holds the UI controls or
widgets that will appear on the screen of an android application or activity screen
VIEW:-
View is a basic building block of UI (User Interface) in android. A view is a small
rectangular box that responds to user inputs.The View class is the base class or we can
say that it is the superclass for all the GUI components in android
ViewGroup is an invisible container of other views (child views) and other ViewGroup.
ViewGroup is a special kind of view that is extended from View as its base class
The View class is the base class or we can say that it is the superclass for all the GUI
components in android. View refer to the android.view.View class, which is the base
class of all UI classes. Some View subclass are TextView, EditText, ImageView,
RadioButtun, etc
5. What are fragments? How do you incorporate fragments into an activity.

Android Fragment is the part of activity, it is also known as sub-activity. There can be
more than one fragment in an activity. Fragments represent multiple screen inside one
activity. Android fragment lifecycle is affected by activity lifecycle because fragments are
included in activity. Each fragment has its own life cycle methods that is affected by
activity life cycle because fragments are embedded in activity. The FragmentManager
class is responsible to make interaction between fragment objects
Eg:- public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Fragment:-
public class Fragment1 extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}
6. How do you create alert dialog control? Explain the process of handling positive
button click event in alert dialog.

Alert Dialog shows the Alert message and gives the answer in the form of yes or no. Alert
Dialog displays the message to warn you and then according to your response, the next step is
processed. Android Alert Dialog is built with the use of three fields: Title, Message area, and
Action Button.
Alert Dialog code has three methods:
setTitle() :- method for displaying the Alert Dialog box Title
setMessage():- method for displaying the message
setIcon() :- method is used to set the icon on the Alert dialog box
Handling Positive button:-

setPositiveButton() is used to create a positive button in alert dialog. As shown in


below

AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(

AlertDialogActivity.this);

// Setting Dialog Title

alertDialog2.setTitle("Confirm Delete...");

// Setting Dialog Message

alertDialog2.setMessage("Are you sure you want delete this file?");

// Setting Icon to Dialog

alertDialog2.setIcon(R.drawable.delete);

// Setting Positive "Yes" Btn

alertDialog2.setPositiveButton("YES",

new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// Write your code here to execute after dialog

Toast.makeText(getApplicationContext(),

"You clicked on YES", Toast.LENGTH_SHORT)

.show();

} });
7. What is an android view. Explain its features and significance.

View is a basic building block of UI (User Interface) in android. A view is a small


rectangular box that responds to user inputs.The View class is the base class. It can refer to
the android.view.View class.
Features(Attributes):-

Significance:-
Basicaly View is a simple building block of a user interface. It is a small rectangular box that
can be TextView, EditText, or even a button. It occupies the area on the screen in a
rectangular area and is responsible for drawing and event handling. View is a superclass of all
the graphical user interface components.
view is used to draw content on the screen of the user’s Android device. A view can be
easily implemented in an Application using the java code. Its creation is more easy in the
XML layout file of the project
8. Write short notes about permission manager in android with an example.
If you decide that your app must access restricted data or perform restricted actions to fulfill a
use case, declare the appropriate permissions.
Types of permission:-
1.Install-time permissions:-
Install-time permissions give your app limited access to restricted data, and they allow your
app to perform restricted actions that minimally affect the system or other apps.
2.Normal permissions:-
These permissions allow access to data and actions that extend beyond your app's sandbox
3.Signature permissions:-
If the app declares a signature permission that another app has defined, and if the two apps
are signed by the same certificate, then the system grants the permission to the first app at
install time. Otherwise, that first app cannot be granted the permission.
4.Runtime permissions:-
It give your app additional access to restricted data, and they allow your app to perform
restricted actions that more substantially affect the system and other apps.
Eg:-
String[] perms = {"android.permission.FINE_LOCATION",
"android.permission.CAMERA"};
int permsRequestCode = 200;
requestPermissions(perms, permsRequestCode);
@Override
public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[]
grantResults){
switch(permsRequestCode){
case 200:
boolean locationAccepted =
grantResults[0]==PackageManager.PERMISSION_GRANTED;
boolean cameraAccepted =
grantResults[1]==PackageManager.PERMISSION_GRANTED;

break;

}
9. Explain the working of date and time pickers in android with code.
Android Date Picker allows you to select the date consisting of day, month and year in your
custom user interface. For this functionality android provides DatePicker and DatePickerDialog
components.
In this tutorial, we are going to demonstrate the use of Date Picker through DatePickerDialog.
DatePickerDialog is a simple dialog containing DatePicker.
In order to show DatePickerDialog , you have to pass the DatePickerDialog id to
showDialog(id_of_dialog)

showDialog(999);
#On calling this showDialog method, another method called onCreateDialog
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
if (id == 999) {
return new DatePickerDialog(this, myDateListener, year, month, day);
}
return null;
}

#In the last step, you have to register the DatePickerDialog listener and override its onDateSet
method.
private DatePickerDialog.OnDateSetListener myDateListener = new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
// arg1 = year
// arg2 = month
// arg3 = day
}
};
10. Explain the different types of dialogs available in android with example

11. Explain the different types of menus.


In android, we have three types of Menus available to define a set of options and actions in our
android applications. The Menus in android applications are the following:
Android Options Menu
Android Context Menu
Android Popup Menu
Android Options Menu:- it is a primary collection of menu items in an android application and
is useful for actions that have a global impact on the searching application.
Android Context Menu:- It is a floating menu that only appears when the user clicks for a long
time on an element and is useful for elements that affect the selected content or context frame.
Android Popup Menu:- It displays a list of items in a vertical list which presents the view that
invoked the menu and is useful to provide an overflow of actions related to specific content.
12. Explain different types of controls. Such as Textbox, button, ckeckbox, etc

13. Explain different types of intent. Explain intent filters.


Intent is to perform an action. It is mostly used to start activity, send broadcast receiver, start services
and send message between two activities. There are two intents available in android as Implicit Intents
and Explicit Intents.

You might also like