0% found this document useful (0 votes)
49 views

Exercise 1 - MC Lab (311118104020)

The document outlines the steps to create a simple Android application that changes a text view's text on button click. It involves creating a new project, designing the layout with a text view, and coding the Java file to set the onClick listener for the button to change the text from "Hello Amal" to "hello CSE". When the application is run, clicking the button successfully changes the displayed text as intended.

Uploaded by

Dhipti E
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)
49 views

Exercise 1 - MC Lab (311118104020)

The document outlines the steps to create a simple Android application that changes a text view's text on button click. It involves creating a new project, designing the layout with a text view, and coding the Java file to set the onClick listener for the button to change the text from "Hello Amal" to "hello CSE". When the application is run, clicking the button successfully changes the displayed text as intended.

Uploaded by

Dhipti E
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/ 4

Ex.

No: 1 Text Edit 311118104020


Date: 2/03/2021

AIM:
To develop a single Android Application to change text on click.

Procedure:
Creating a New Project:
Step1: Open Android Studio and then click on File -> New -> New project.
Step2: Then type the Application name as “HelloWorld″ and click Next.
Step3: Then select the Minimum SDK as shown below and click Next.
Step4: Then select the Empty Activity and click Next.
Step5: Finally click Finish.
Step6: It will take some time to build and load the project.
Step7: After completion it will look as given below.
Designing layout for the Android Application:
Step8: Click on app -> res -> layout -> activity_main.xml.
Step9: Click on Design and drag and drop text view.
Java Coding for the Android Application:
Step10: Click on app -> java -> com.example.HelloWorld -> MainActivity.
Step11: Type the code given below.

Code for 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">

<TextView
android:id="@+id/helloButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onHelloButtonClick"
android:text="Hello Amal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Code for MainActivity.java:


package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView
import java.text.BreakIterator;
public class MainActivity extends AppCompatActivity
TextView helloButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
helloButton = (TextView) findViewById(R.id.helloButton);
}
public void onHelloButtonClick(View v)
{
helloButton.setText("hello CSE");
}
}

OUTPUT:
RESULT:
Thus a Simple Android Application to change text on click is developed and executed successfully.

You might also like