0% found this document useful (0 votes)
35 views24 pages

Question Bank MAD PT2 Exam 22-23-CO-IF

The document contains questions and answers related to various Android concepts like content providers, activities, sensors, intents, services, animations, databases, location and more. It provides definitions and explanations of these concepts along with code snippets and diagrams.

Uploaded by

atharvbowlekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views24 pages

Question Bank MAD PT2 Exam 22-23-CO-IF

The document contains questions and answers related to various Android concepts like content providers, activities, sensors, intents, services, animations, databases, location and more. It provides definitions and explanations of these concepts along with code snippets and diagrams.

Uploaded by

atharvbowlekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Question Bank MAD (22617) - PT2

Class/Course: CO6I (A+B) and IF6I


Academic Year 2022-2023

1. Explain significance of content provider?


Content Providers are used to share data between two applications. This can be implemented in
two ways:
1. When you want to implement the existing content provider in another application.
2. When you want to create a new content provider that can share its data with other applications.

2. What is Activity in android?


An Android activity is one screen of the Android app's user interface. In that way an Android
activity is very similar to windows in a desktop application. An Android app may contain one or
more activities, meaning one or more screens. The Android app starts by showing the main
activity, and from there the app may make it possible to open additional activities.

3. Explain Sensors in android with its Types.

Android-powered devices have built-in sensors that measure motion, orientation, and various
environmental conditions. These sensors are capable of providing raw data with high precision and
accuracy, and are useful if you want to monitor three-dimensional device movement or positioning,
or you want to monitor changes in the ambient environment near a device.

The Android platform supports three broad categories of sensors:

 Motion sensors

These sensors measure acceleration forces and rotational forces along three axes. This category
includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.

 Environmental sensors

These sensors measure various environmental parameters, such as ambient air temperature and
pressure, illumination, and humidity. This category includes barometers, photometers, and
thermometers.

 Position sensors

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 1


These sensors measure the physical position of a device. This category includes orientation sensors
and magnetometers.

4. What is Intent? State its types?

Android Intent is the message that is passed between components such as activities, content
providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke
activity, broadcast receivers etc.

There are two types of intents in android: implicit and explicit.

1) Implicit Intent

It doesn't specify the component. In such case, intent provides information of available components
provided by the system that is to be invoked.

2) Explicit Intent

It specifies the component. In such case, intent provides the external class to be invoked.

5. What is Service in android? State its types?

Android service is a component that is used to perform operations on the background such as
playing music, handle network transactions, interacting content providers etc. It doesn't has any UI
(user interface).The service runs in the background indefinitely even if application is
destroyed.Moreover, service can be bounded by a component to perform interactivity and inter
process communication (IPC).

There can be two forms of a service.The lifecycle of service can follow two different paths: started or
bound.

1. Started
2. Bound

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 2


1) Started Service

A service is started when application component (like activity) starts or calls startService() method,
now it runs in the background indefinitely. It is stopped by stopService() method. The service can
stop itself by calling the stopSelf() method.

2) Bound Service

A service is bound when another component (e.g. client) calls bindService() method. A bound
service offers a client-server interface that allows components to interact with the service, send
requests, get results, and even do so across processes with interprocess communication (IPC).The
client can unbind the service by calling the unbindService() method.The service cannot be stopped
until all clients unbind the service.

6. Draw the neat diagram of activity life cycle

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 3


7. State the uses of Intent in Android.
Intent is a messaging object you can use to request an action from another app component.
Intents are used for facilitating communication between components like Activities, Services and
Broadcast Receivers.

8. What is Animation? State its Types.

Animation is the process of creating motion and shape change. Animation in android is possible in 3
ways:

1. Property Animations — They are used to alter property of objects (Views or non view objects).
We specify certain properties(like translateX, TextScaleX) of the objects to change. Various
characteristics of animation which can be manipulated are animation duration, whether to reverse
it and for how many times we want to repeat the animation etc. They were introduced in Android
3.0 (API level 11).

2. View Animations — They are used to do simple animations like changing size, position, rotation,
control transparency. They are easy to build and are very fast but have their own constraints. For
eg — Their state changes but their property does not change. View animations will be covered in
part 2.

3. Drawable Animations — This is used to do animation using drawables. An XML file specifying
various list of drawables is made which are run one by one just like a roll of a film. This is not
much used so I won‟t cover it.

9. What is TTS feature of Android?

Text to speech, abbreviated as TTS, is a form of speech synthesis that converts text into spoken
voice output. Text to speech systems were first developed to aid the visually impaired by offering a
computer-generated spoken voice that would "read" text to the user. Android TTS API offers
multiple-language support, control of voice characteristics and features, file output, and so on.
With just a small number of lines of code, you can make your apps reach out to a wider audience.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 4


10.Draw the neat diagram of Fragment life cycle

11. Explain different ways to handle databases in android?


There are basically four different ways to handle databases in an Android :

1. Shared Preferences

You should use this to save primitive data in key-value pairs. You have a key, which must be a
String, and the corresponding value for that key, which can be one of: boolean, float, int, long or
string. Internally, the Android platform stores an app‟s Shared Preferences in an xml file in a private
directory.

2. Internal Storage

The Internal Storage data storage method is specifically for those situations where you need to store
data to the device filesystem, but you do not want any other app (even the user) to read this data.
Data stored using the Internal Storage method is completely private to your application, and are
deleted from the device when your app is uninstalled.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 5


3. External Storage

To save (and/or read) files to the device‟s external storage, your app must request for the
WRITE_EXTERNAL_STORAGE permission. If you only want to read from the External Storage
without writing, request for the READ_EXTERNAL_STORAGE permission. The
WRITE_EXTERNAL_STORAGE permission grants both read/write access.

4. SQLite database

Finally, Android provides support for apps to use SQLite databases for data storage. Databases
created are app specific, and are available to any class within the app, but not to outside applications.

12. Name any 4 methods to get location data in android.

The Location object represents a geographic location which can consist of a latitude, longitude, time
stamp, and other information such as bearing, altitude and velocity. There are following important
methods which you can use with Location object to get location specific information −

Sr.No. Method & Description

1
float distanceTo(Location dest)
Returns the approximate distance in meters between this location and the given location.

2
float getAccuracy()
Get the estimated accuracy of this location, in meters.

3
double getAltitude()
Get the altitude if available, in meters above sea level.

4
float getBearing()
Get the bearing, in degrees.

5
double getLatitude()
Get the latitude, in degrees.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 6


6
double getLongitude()
Get the longitude, in degrees.

7
float getSpeed()
Get the speed if it is available, in meters/second over ground.

8
boolean hasAccuracy()
True if this location has an accuracy.

9
boolean hasAltitude()
True if this location has an altitude.

10
boolean hasBearing()
True if this location has a bearing.

11
boolean hasSpeed()
True if this location has a speed.

12
void reset()
Clears the contents of the location.

13
void setAccuracy(float accuracy)
Set the estimated accuracy of this location, meters.

14
void setAltitude(double altitude)
Set the altitude, in meters above sea level.

15
void setBearing(float bearing)
Set the bearing, in degrees.

16
void setLatitude(double latitude)
Set the latitude, in degrees.

17
void setLongitude(double longitude)
Set the longitude, in degrees.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 7


18
void setSpeed(float speed)
Set the speed, in meters/second over ground.

19
String toString()
Returns a string containing a concise, human-readable description of this object.

13.Enlist (Explain) steps to develop android application. (If explain comes in


question write with explanation or else mention only steps. Also see the
weightage of marks if for 4 marks should write with explanation.)

Creation of Android App Step by Step:

Step 1: Start with Android Studio

The most common IDE for Android development is Android Studio, which comes directly from
Google itself.

Step 2: Installation of Java Development Kit (JDK)

After the installation of Android Studio, You also need to install Java on your machine to use
Android Studio. The JDK is able to interpret and compile your code for the application development.

Step 3: Start Your Project

Choose „Start a new Android Studio Project‟ option. Enter the name you want for your application
and your „company domain‟. All these elements will be used to create your package name in a format
like: com.companyname.appname

Step 4: Select Activity

Moreover, you‟ll be given the option to pick the way you want the app to look at the beginning. This
will be the look of your main „Activity Module‟ which is basically the main page of your app. There
are various fields available which you have to choose according to your app needs, such as templates,
title, access to Google maps, full-screen activity, blank activity etc. As per my view, it‟s better to go
for „Basic Activity‟ to keep things as simple as possible and for all intents and purposes.

Step 5: Selecting the Layout

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 8


Now, you have to choose a layout name for the selected activity. This will define that where
elements like images and menus go and what fonts you‟ll use. Choose a name for the menu and title
as well. Pick something attractive for the title, as your users will be able to see this at some points.

Step 6: Edit the Welcome Message

Go to the activity_main.xml tab if it is not open. Click and drag the “Hello, world!” from the upper
left corner of the phone display to the center of the screen. Then go to the values folder, and double-
click the strings.xml file. In this file, find the line “Hello world!” and add “Welcome to my App!”

Step 7: Adding Button to your Activity

In the Palette menu to the left of display, find Button. Click and drag Button to be positioned beneath
welcome message. Afterward, go to properties and find the field for text. Change the text from “New
Button” to “Next Page”.

Now go back to your content_main.xml and click on the button. In the right corner, where you have
your parameters for the button, you will catch an option called „onClick‟. Click on this and then
select the „onClick‟. By doing this, you have told Android Studio that you want to associate the
section of code with the button created.

Step 8: Test your App

Finally, all that‟s missing to do is run the app you just made. Simple go to „run‟ along the top and
then select „run app‟ from the drop-down menu. Follow the steps to launch the emulator running
your app.

14.Write the syntax for Intent-filter tag


<intent-filter>

syntax:

<intent-filter android:icon="drawable resource"


android:label="string resource"
android:priority="integer" >
. . .
</intent-filter>

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 9


15.Enlist (explain) the steps to publish the Android application. (if explain comes
in question write with explanation or else mention only steps. Also see the
weightage of marks if for 4 marks should write with explanation.)

1. Create an account

Firstly, To publish your app on google play store, you need to have account on google. You may
have already personal email account with them but for your app it's better to separate one for manage
your app(s) easily. You would have to pay a registration fees of 25 USD, using Google payments,
While registering your publisher account. After that, a verification mail would be sent to you and
then you sign in to your developer console, where all action would take place.

2. Familiarise yourself with Developer Console

Developer console is starting point and main dashboard for publishing tools and operations. Before
you go ahead, familiarise yourself with list of merchant countries and developer countries. You need
to review list of merchant countries if you want to sell apps or in app purchases or have subscriptions
and list of developer countries will tell you about locations where distribution to Google play users is
supported. Apart from this, also looks the Google Play‟s Terms and conditions.

3. Fill in the necessary account details

After this, you have to provide your complete account details like you have to provide your
developer name, the name which would be displayed in Google Play Store. You will have to wait for
anything between just a little and 48 hours, after filling the details for Google play developer
registration to be processed.

4. Link your merchant account

If you have a paid app or subscription or in app purchases, then you have to inter link your google
payments merchant account and developer profile. It can be used for tax and financial identification
as well as monthly payout from sale.

5. Upload your app

When you are sign in your Google Play developer console, click on “Add new application” from
“All Applications tab”. After this select correct “Default Language” from drop down menu and then
type “title” of your app which would be appear on Google Play store. Then, select “Upload APK”

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 10


button to view on new page which would be your homepage for app. Time taken to upload file
depend on your app size. App will be in drafts until or unless you publish it.

6. Alpha and beta testing of app

It is essential to test it with sample of end users to get feedback of app before launch your app even
Google play take care of this as well. In section of your app “APK” of developer console, you will
find option related to “Alpha Testing” and “Beta Testing”. After you uploaded your app‟s “APK” file
you can use these options for receive URL that can be shared with testers. By using this link, Testers
can download app beta or alpha version. Your testers can not provide reviews and feedback on app
page. Now you use this feedback to make relevant changes and optimise your app before publishing
in app store.

7. Provide details for store listing

After uploading “APK” file go to “Store listing” tab. Over there you need to add details of app like
“Full description” and “Short description”. Along with this add categorisation, contact details, link of
promo video if you have, add screenshots and other necessary details to app. After complete
mandatory fields click on “Save” button. You can update your store listing anytime.

8. Add pricing and distribution details

Now move on next tab, which is “Pricing and Distribution” and select it is “Paid” or “Free” app. You
also select distribution countries and check boxes stating your app complies with content guidelines.
If your app is an game one, then you can put in limelight using “Google Play for Game” option. Now
save changes and move on next step.

9. Publishing the application

When all three tabs “Pricing and Distribution”, “Store Listing” and “APK” have been filled then
appear a green check mark next to them you are all ready to publish app in Google Play. After then
click on “Publish this app” button under “Ready to Publish” drop down menu at top right corner of
Developer console. A confirmation bar would show up stating your app would appear shortly in
Google Play Store.

10. Device Filtering option

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 11


There are series of extra option that might not seem to be important to publish the app but they can
prevent app from negative feedback. There is also option to manually filter non compatible devices
or problematic so make the most use of it to filter out any negativities and stay on the top.

16.Explain Google Map with types.

Google map displays your current location, navigate location direction, search location etc. Google
Maps provides four types of maps. They are −

 ROADMAP (normal, default 2D map)− This is the default type. If you haven't chosen any of
the types, this will be displayed. It shows the street view of the selected region.
 SATELLITE (photographic map)− This is the map type that shows the satellite images of
the selected region.

 HYBRID (photographic map + roads and city names)− This map type shows the major
streets on satellite images.

 TERRAIN (map with mountains, rivers, etc.) − This is the map type that shows the terrain
and vegetation

17.Describe the types of permissions used while developing android applications.

Permissions are divided into several protection levels. The protection level affects whether runtime
permission requests are required. There are three protection levels that affect third-party
apps: normal, signature, and dangerous permissions.

Normal permissions

Normal permissions cover areas where your app needs to access data or resources outside the app's
sandbox, but where there's very little risk to the user's privacy or the operation of other apps. For
example, permission to set the time zone is a normal permission.

Signature permissions

The system grants these app permissions at install time, but only when the app that attempts to use a
permission is signed by the same certificate as the app that defines the permission.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 12


Dangerous permissions

Dangerous permissions cover areas where the app wants data or resources that involve the user's
private information, or could potentially affect the user's stored data or the operation of other apps.
For example, the ability to read the user's contacts is a dangerous permission. If an app declares that
it needs a dangerous permission, the user has to explicitly grant the permission to the app. Until the
user approves the permission, your app cannot provide functionality that depends on that permission.

Special permissions

There are a couple of permissions that don't behave like normal and dangerous
permissions. SYSTEM_ALERT_WINDOW and WRITE_SETTINGS are particularly sensitive, so
most apps should not use them. If an app needs one of these permissions, it must declare the
permission in the manifest, and send an intent requesting the user's authorization. The system
responds to the intent by showing a detailed management screen to the user.

Starting from Android 6.0 (API 23), users are not asked for permissions at the time of installation
rather developers need to request for the permissions at the run time. Only the permissions that
are defined in the manifest file can be requested at run time.

Permissions Required at:


1. Install-Time Permissions: If the Android 5.1.1 (API 22) or lower, the permission is
requested at the installation time at the Google Play Store.

If the user Accepts the permissions, the app is installed. Else the app installation is cancelled.

2. Run-Time Permissions: If the Android 6 (API 23) or higher, the permission is requested at
the run time during the runnnig of the app.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 13


If the user Accepts the permissions, then that feature of the app can be used. Else to use the feature,
the app requests the permission again. So, now the permissions are requested at runtime.

18.Explain the activity life cycle with neat diagram.


Refer the diagram given above.

Activity is one of the building blocks of Android OS. In simple words Activity is a screen that user
interact with. Every Activity have a predefined life-cycle methods. Activity in android has lifecycle
like created, started, resumed, paused, stopped or destroyed. These different states are known
as Activity Lifecycle.

onCreate (): Called then the activity is created. Used to initialize the activity, for example create
the user interface.
onStart ():called when activity is becoming visible to the user.
onResume (): Called if the activity get visible again and the user starts interacting with the
activity again. Used to initialize fields, register listeners, bind to services, etc.
onPause (): Called once another activity gets into the foreground. Always called before the
activity is not visible anymore. Used to release resources or save application data. For example
you unregister listeners, intent receivers, unbind from services or remove system service
listeners.
onStop (): Called once the activity is no longer visible. Time or CPU intensive shutdown
operations, such as writing information to a database should be down in the onStop() method.
This method is guaranteed to be called as of API 11.
onDestroy (): called before the activity is destroyed.

19.State syntax to create Text View and Image button with any two attributes of
each.

Text View:
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Your name" />

Attributes/Properties of TextView:

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 14


 id: Supply an identifier name of this view, to later retrieve it with View.findViewByID()
or Activity.findViewById()
 alpha: alpha property of the view as a value between 0 (entirely transparent) and
1(Completely Opaque). [flag]
 auto link: Controls whether links such as urls and email addresses are automatically
found and converted to clickable links.[flag]
 gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text like left, right, center, top, bottom, center_vertical,
center_horizontal etc
 text: text attribute is used to set the text in a text view. We can set the text in xml as well
as in the java class.
 textColor: textColor attribute is used to set the text color of a text view. Color value is in
the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
 textSize: textSize attribute is used to set the size of text of a text view. We can set the
text size in sp(scale independent pixel) or dp(density pixel).
 textStyle: textStyle attribute is used to set the text style of a text view. The possible text
styles are bold, italic and normal. If we need to use two or more styles for a text view
then “|” operator is used for that.
 background: background attribute is used to set the background of a text view. We can
set a color or a drawable in the background of a text view.
 padding: padding attribute is used to set the padding from left, right, top or bottom. In
above example code of background we also set the 10dp padding from all the sides of
text view.

ImageButton:
Syntax :
<ImageButton
android:id="@+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add_icon" />

Attributes/Properties of ImageButton:
 id: id is an attribute used to uniquely identify a image button.

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 15


 src: src is an attribute used to set a source file of image or you can say image in your
image button to make your layout look attractive.
 background: background attribute is used to set the background of an image button. We
can set a color or a drawable in the background of a Button.
 padding: padding attribute is used to set the padding from left, right, top or bottom of
the ImageButton.

20.Write a program to accept and display personal information of the student.

Xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:text="Enter Your name"
android:textSize="20dp" />

<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt1"
android:ems="20"
android:textSize="20dp" />

<TextView

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 16


android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:text="Enter Your phone"
android:textSize="20dp" />

<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt2"
android:inputType="phone"
android:ems="20"
android:textSize="20dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/password"
android:ems="20"
android:text="Submit"
android:textSize="20dp" />
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/button"
android:textSize="20dp" />
</RelativeLayout>

Java:
package com.example.exp7_2;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 17
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


EditText name,phone;
Button btn;
TextView txt3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton(){
name=(EditText) findViewById(R.id.username);
phone=(EditText) findViewById(R.id.password);
btn=(Button)findViewById(R.id.button);
txt3=(TextView) findViewById(R.id.txt3);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String nameValue=name.getText().toString();
String phoneValue=phone.getText().toString();
txt3.setText("Your Name is "+nameValue+"\nYour Phone Number is "+phoneValue);
}
});
}
}

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 18


21.Develop a program to implement Auto Complete Text View.
Xml Code:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MSBTE 6th Sem Subjects"
android:textColor="@color/teal_200"
android:textSize="30sp"
android:layout_margin="20dp"
android:textAlignment="center"
/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="20dp"
android:id="@+id/AutoCompleteTextView"
android:ems="20">
<requestFocus/>
</AutoCompleteTextView>

</LinearLayout>

Java Code

package com.example.exp8_2;
import androidx.appcompat.app.AppCompatActivity;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {

String[] sub={"MAD","WBP","PWP","ETI","MGT","CPE"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 19


setContentView(R.layout.activity_main);

ArrayAdapter<String> arrayAdapter=new
ArrayAdapter<String>(this,android.R.layout.select_dialog_item,sub);

AutoCompleteTextView actv=(AutoCompleteTextView)
findViewById(R.id.AutoCompleteTextView);

actv.setAdapter(arrayAdapter);
actv.setThreshold(1);
actv.setTextColor(Color.RED);
}
}

22.Write a program to create a text field and button “Navigate”. When you enter
www.google.com and press on navigate button it should open the google page.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:ems="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="172dp"
android:text="Navigate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 20


app:layout_constraintTop_toBottomOf="@+id/editText" />

</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.implicit_intent_navigate;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.content.Intent;
import android.net.Uri;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

Button button;
EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button = findViewById(R.id.button);
editText = findViewById(R.id.editText);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);

}
});
}
}

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 21


23.Write a program to display circular progress bar.

XML CODE:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="Circular Progress Bar"
android:textSize="20sp"
android:layout_marginVertical="30dp"
android:layout_marginHorizontal="40dp"
android:onClick="display"
/>
<ProgressBar
android:layout_marginHorizontal="150dp"
android:id="@+id/ProgressBar"
android:layout_width="100dp"
android:visibility="invisible"
android:layout_height="100dp" />
</LinearLayout>

JAVA CODE:
package com.example.exp13_1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b1;
ProgressBar pb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button);
pb=(ProgressBar) findViewById(R.id.ProgressBar);
}
public void display(View view){
pb.setVisibility(View.VISIBLE);
}
}

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 22


24.Write a program to display an image using imageview and a button named as
change image. Once you click on button another image should get displayed
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="249dp"
android:layout_weight="1"
android:src="@drawable/sun_spring_green_forest"/>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="change image" />
</LinearLayout>

MainActivity.java
package com.example.changeimage;

import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.view.View;

public class MainActivity extends Activity {

Button button;
ImageView img;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

addListenerOnButton();

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 23


public void addListenerOnButton()
{
img=(ImageView)findViewById(R.id.imageView1);
button=(Button)findViewById(R.id.button1);

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
img.setImageResource(R.drawable.palombaggia_beach_sunny);
}
});

}
}

MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 24

You might also like