MAD QB Solved
MAD QB Solved
2. java folder: The source code files written in Java programming language
reside in this folder. You can see that the java file of the activity named
"MainActivity.java" is automatically created in this folder.
3. res folder: The resource files are contained in this folder. Resources basically
mean all the needed files except the source code. The media, image and
layout files residing in the resources folder are accessed via Java code written
in MainActivity.java.
4. Some of the key files and directory(folders) are there ,Let's see each folder in
detail:
5. src - Java source files associated with your project.
6. res - Resource files associated with your project. All graphics, strings, layouts,
and other
7. resource files are stored in the resource file hierarchy under the res
directory.
8. res/layout - XML layout files that describe the views and layouts for each
activity and for partial views such as list items.
9. res/values - XML files which store various attribute values. These include
strings.xml, dimens.xml, styles.xml, colors.xml, themes.xml, and so on.
10. res/drawable - Here we store the various density-independent graphic assets
used in our application.
11. res/mipmap - most commonly used for application icons.
6. Define Emulator.
ANS
An Emulator is a device which mimics the functionality of an actual physical device
such as a smartphone
It allows you to test and debug applications without needing a physical device
• An Android Emulator is a device that simulates an Android device on your
system. Suppose we want to run our android application that we code. One
option is that we will run this on our Android Mobile by Enabling USB
Debugging on our mobile.
<TableRow>
<TextView android:text="Password:"/>
<EditText android:id="@+id/password" android:inputType="textPassword"/>
</TableRow>
<TableRow>
<Button android:text="Login" android:onClick="login"/>
</TableRow>
</TableLayout>
19. Develop a program to perform addition,subtraction,multiplication,Division of
Two numbers.
ANS
import android.os.Bundle;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 = findViewById(R.id.num1);
num2 = findViewById(R.id.num2);
add = findViewById(R.id.add);
subtract = findViewById(R.id.subtract);
multiply = findViewById(R.id.multiply);
divide = findViewById(R.id.divide);
result = findViewById(R.id.result);
add.setOnClickListener(v ->
result.setText(String.valueOf(Integer.parseInt(num1.getText().toString()) +
Integer.parseInt(num2.getText().toString()))));
subtract.setOnClickListener(v ->
result.setText(String.valueOf(Integer.parseInt(num1.getText().toString()) -
Integer.parseInt(num2.getText().toString()))));
multiply.setOnClickListener(v ->
result.setText(String.valueOf(Integer.parseInt(num1.getText().toString()) *
Integer.parseInt(num2.getText().toString()))));
divide.setOnClickListener(v ->
result.setText(String.valueOf(Integer.parseInt(num1.getText().toString()) /
Integer.parseInt(num2.getText().toString()))));
}
}
20. Write down steps to install android studio and android sdk.
ANS
1. Visit
https://developer.android.com/studio/install
to get the Android Studio executable or zip file.
2. Click on the Download Android Studio Button.
3. Click on the “I have read and agree with the above terms and conditions”
checkbox followed by the download button.
4.Select Android Virtual Device and click on Next >
5. It will show the installation path, default it could be in C:\Program Files\Android\,
If you want to change the installation directory, you can freely use the Browse
button and give the location and click on Next.
6. Click on Install.
7.Actual installation in progress..
8.Tick on Start Android Studio and Click on Finish.
• This is how, we can install Android Studio on windows 10.
• as we tick on Start Android Studio option, the Android Studio will launch
automatically as soon as we click on Finish button.
• Meanwhile, it will be finding the available SDK components.
10. It will ask for the Android Studio installation type. Mostly we can go with Standard setup, if
you have any specific configuration setup then you can select the Custom option to manual setup.
Now choose Standard Setup, and click on Next.
11.Now choose the theme, whether the Light theme or the Dark one. The light one is
called the IntelliJ theme whereas the dark theme is called Dracula. Choose as
required.
• Now it is time to download the SDK components.
12.It will download all necessary SDK components to launch the Android Studio and
setting up the environment.
13. After download and installation click on Finish.
Android Emulator:
An Android emulator or an Android Virtual Device (AVD) is a software that
emulates Android OS and its functionality on your computer. Notably, it creates a
virtual representation of a phone or any other device. It then runs the Android
operating system as if it was running on a physical implementation of that device
22. Write a Program to place Name, Age and Mobile no. centrally on display screen
using Relative Layout.
ANS
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/nameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"/>
<EditText
android:id="@+id/nameInput"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/nameLabel"
android:layout_centerHorizontal="true"
android:hint="Enter Name"/>
<TextView
android:id="@+id/ageLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age:"
android:textSize="18sp"
android:layout_below="@id/nameInput"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/ageInput"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/ageLabel"
android:layout_centerHorizontal="true"
android:hint="Enter Age"
android:inputType="number"/>
<TextView
android:id="@+id/mobileLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile No:"
android:textSize="18sp"
android:layout_below="@id/ageInput"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/mobileInput"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@id/mobileLabel"
android:layout_centerHorizontal="true"
android:hint="Enter Mobile No"
android:inputType="phone"/>
</RelativeLayout>
JAVA CODE
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.EditText;
// Reference to UI elements
EditText nameInput = findViewById(R.id.nameInput);
EditText ageInput = findViewById(R.id.ageInput);
EditText mobileInput = findViewById(R.id.mobileInput);
}
}