Skip to document

ADF Journal

android practical journal
Course

computer science (csitbbs)

94 Documents
Students shared 94 documents in this course
Academic year: 2022/2023
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
Shri Ramsheth Thakur College of Commerce & Science

Comments

Please sign in or register to post comments.

Preview text

SAHIL KHAN A 4317

Practical 1

Aim: Install Android Studio and Run Hello World App.

Android Studio provides a complete integrated development environment (IDE) including an advanced code editor and a set of app templates. In addition, it contains tools for development, debugging, testing, and performance that make it faster and easier to develop apps. You can test your apps with a large range of preconfigured emulators or on your own mobile device, build production apps, and publish on the Google Play store.

How to install android studio on PC’s :

  1. Navigate to the Android developers site and follow the instructions to download and install Android Studio.

  2. Accept the default configurations for all steps, and ensure that all components are selected for installation.

  3. After finishing the install, the Setup Wizard will download and install some additional components including the Android SDK. Be patient, this might take some time depending on your Internet speed, and some of the steps may seem redundant.

  4. When the download completes, Android Studio will start, and you are ready to create your first project.

Task 2: Create the Hello World app:

In this task, you will create an app that displays "Hello World" to verify that Android studio is correctly installed, and to learn the basics of developing with Android Studio.

2 Create the app project

1 Android Studio

2 the main Welcome to Android Studio window, click Start a new Android Studio project. In the Create Android Project window, enter Hello World for the Application name.

SAHIL KHAN A 4317

  1. Verify that the default Project location is where you want to store your Hello World app

and other Android Studio projects, or change it to your preferred directory.

  1. Accept the default android.example for Company Domain, or create a unique

company domain. If you are not planning to publish your app, you can accept the default. Be aware that changing the package name of your app later is extra work.

  1. Leave unchecked the options to Include C++ support and Include Kotlin support, and

click next.

  1. On the Target Android Devices screen, Phone and Tablet should be selected. Ensure that API 15: Android 4.0 IceCreamSandwich is set as the Minimum SDK; if it is not, use the popup menu to set it.

SAHIL KHAN A 4317

10 Configure Activity screen appears (which differs depending on which template you chose in the previous step). By default, the empty Activity provided by the template is named MainActivity. You can change this if you want, but this lesson uses MainActivity.

SAHIL KHAN A 4317

11 sure that the Generate Layout file option is checked. The layout name by default is activity_main. You can change this if you want, but this lesson uses activity_main.

12 sure that the Backwards Compatibility (App Compat) option is checked. This ensures that your app will be backwards-compatible with previous versions of Android.

13 Finish.

Android Studio creates a folder for your projects, and builds the project with Gradle (this may take a few moments).

Tip: See the Configure your build developer page for detailed information.

You may also see a "Tip of the day" message with keyboard shortcuts and other useful tips.

Click Close to close the message.

The Android Studio editor appears. Follow these steps:

1 the activity_main tab to see the layout editor.

2 the layout editor Design tab, if not already selected, to show a graphical rendition of the layout as shown below.

3 the MainActivity tab to see the code editor as shown below.

SAHIL KHAN A 4317

2 Explore the app and res folders

All code and resources for the app are located within the app and res folders.

  1. Expand the app folder, the java folder, and the com.example.android folder to see the MainActivity java file. Double-clicking the file opens it in the code editor.

The java folder includes Java class files in three subfolders, as shown in the figure above.

The com.example.hello (or the domain name you have specified) folder contains all the files for an app package. The other two folders are used for testing and described in another lesson. For the Hello World app, there is only one package and it contains

MainActivity. The name of the first Activity (screen) the user sees, which also initializes app-wide resources, is customarily called MainActivity (the file extension is omitted in the Project > Android pane ).

  1. Expand the res folder and the layout folder, and double-click the activity_main file to open it in the layout editor.

SAHIL KHAN A 4317

The res folder holds resources, such as layouts, strings, and images. An Activity is usually associated with a layout of UI views defined as an XML file. This file is usually named after its Activity.

SAHIL KHAN A 4317

<Button android:id="@+id/button2" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/button1" android:layout_toLeftOf="@+id/button3" android:layout_toStartOf="@+id/button3" android:text="2" />

<Button android:id="@+id/button3" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content"

android:layout_height="wrap_content" android:layout_alignTop="@+id/button2" android:layout_centerHorizontal="true" android:text="3" />

<Button android:id="@+id/button4"

style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button1" android:layout_toLeftOf="@+id/button2" android:text="4" />

<Button android:id="@+id/button5" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/button4" android:layout_alignLeft="@+id/button2" android:layout_alignStart="@+id/button2" android:text="5" />

<Button android:id="@+id/button6" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button3" android:layout_alignStart="@+id/button3" android:layout_below="@+id/button3" android:text="6"

SAHIL KHAN A 4317

/>

<Button android:id="@+id/button7" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button4" android:layout_toLeftOf="@+id/button2" android:text="7" />

<Button android:id="@+id/button8" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button5" android:layout_alignStart="@+id/button5" android:layout_below="@+id/button5"

android:text="8" />

<Button android:id="@+id/button9" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button6" android:layout_alignStart="@+id/button6" android:layout_below="@+id/button6" android:text="9" />

<Button android:id="@+id/buttonadd" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/edt1" android:layout_alignRight="@+id/edt1" android:layout_alignTop="@+id/button3" android:layout_marginLeft="46dp" android:layout_marginStart="46dp" android:layout_toRightOf="@+id/button3" android:text="+" />

<Button android:id="@+id/buttonsub" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content"

style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button7" android:layout_toLeftOf="@+id/button2" android:text="." /> <Button

android:id="@+id/button0" style="? android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button8" android:layout_alignStart="@+id/button8" android:layout_below="@+id/button8" android:text="0" /> <Button android:id="@+id/buttonC" style="? android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button9" android:layout_alignStart="@+id/button9" android:layout_below="@+id/button9" android:text="C" /> <Button

android:id="@+id/buttondiv" style="? android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/buttonmul" android:layout_alignLeft="@+id/buttonmul" android:layout_alignRight="@+id/buttonmul" android:layout_alignStart="@+id/buttonmul" android:layout_below="@+id/buttonmul" android:text="/" /> <Button android:id="@+id/buttoneql" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignEnd="@+id/buttondiv" android:layout_alignLeft="@+id/button10" android:layout_alignRight="@+id/buttondiv" android:layout_alignStart="@+id/button10" android:layout_below="@+id/button0" android:layout_marginTop="37dp" android:text="=" />

</RelativeLayout>

MainActivity

package com.example;

import androidx.appcompat.app; import android.os; import android.view; import android.widget; import android.widget;

public class MainActivity extends AppCompatActivity {

Button button0, button1, button2, button3, button4, button5, button6, button7, button8, button9, buttonAdd, buttonSub, buttonDivision, buttonMul, button10, buttonC, buttonEqual;

EditText _EditText;

button3(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "3"); } });

button4(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "4"); } });

button5(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "5"); } });

button6(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "6"); } });

button7(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "7"); } });

button8(new View() {

@Override public void onClick(View v) { _EditText(_EditText() + "8"); } });

button9(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "9"); } });

button0(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "0"); } });

buttonAdd(new View() { @Override public void onClick(View v) {

if (_EditText == null) { _EditText(""); } else { mValueOne = Float. parseFloat (_EditText() + ""); _Addition = true; _EditText(null); } } });

buttonSub(new View() { @Override public void onClick(View v) { mValueOne = Float. parseFloat (_EditText() + ""); _Subtraction = true; _EditText(null);

_EditText(mValueOne * mValueTwo + ""); _Multiplication = false; }

if (_Division == true) {

_EditText(mValueOne / mValueTwo + ""); _Division = false; } } });

buttonC(new View() { @Override public void onClick(View v) { _EditText(""); } });

button10(new View() { @Override public void onClick(View v) { _EditText(_EditText() + "."); } }); } }

Output:

In this output I have did addition of number shown in diagrammatic
representation
Was this document helpful?

ADF Journal

Course: computer science (csitbbs)

94 Documents
Students shared 94 documents in this course
Was this document helpful?
SAHIL KHAN A 4317
Practical 1
Aim: Install Android Studio and Run Hello World App.
Android Studio provides a complete integrated development environment (IDE) including an
advanced code editor and a set of app templates. In addition, it contains tools for
development, debugging, testing, and performance that make it faster and easier to develop
apps. You can test your apps with a large range of preconfigured emulators or on your own
mobile device, build production apps, and publish on the Google Play store.
How to install android studio on PC’s :
1. Navigate to the Android developers site and follow the instructions to download and
install Android Studio .
2. Accept the default configurations for all steps, and ensure that all components are
selected for installation.
3. After finishing the install, the Setup Wizard will download and install some additional
components including the Android SDK. Be patient, this might take some time depending on
your Internet speed, and some of the steps may seem redundant.
4. When the download completes, Android Studio will start, and you are ready to create
your first project.
Task 2: Create the Hello World app:
In this task, you will create an app that displays "Hello World" to verify that Android studio is
correctly installed, and to learn the basics of developing with Android Studio.
2.1 Create the app project
1. Open Android Studio
2. In the main Welcome to Android Studio window, click Start a new Android Studio project.
In the Create Android Project window, enter Hello World for the Application name.
1