0% found this document useful (0 votes)
61 views11 pages

Mad 18

This document contains code for an Android application that calculates the factorial of a number. The main activity contains an edit text for inputting a number and a button to calculate the factorial. When the button is clicked, it gets the number from the edit text, calculates the factorial in a loop, and passes the result to a new activity. The new activity displays the number and its factorial in two text views.

Uploaded by

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

Mad 18

This document contains code for an Android application that calculates the factorial of a number. The main activity contains an edit text for inputting a number and a button to calculate the factorial. When the button is clicked, it gets the number from the edit text, calculates the factorial in a loop, and passes the result to a new activity. The new activity displays the number and its factorial in two text views.

Uploaded by

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

Name: Ekambe Ganesh Dattatraya

Roll No. :53

Practical No. : 18

Exercise
package com.example.exp18_1;
import androidx.appcompat.app.AppCompatActivity; import
android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText;

public class MainActivity extends AppCompatActivity


{ EditText editText;
Button btnNavigate; String
text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnNavigate=findViewById(R.id.btnNavigate);
btnNavigate.setOnClickListener(new
View.OnClickListener()
{

@Override
public void onClick(View v) {
editText=findViewById(R.id.edittext);
text=editText.getText().toString().trim(
); if(text.equals("www.youtube.com"))
{

go();

}}});

public void go()


{

Uri uri=Uri.parse("https://www.youtube.com");
Intent intent=new
Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
}

<?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">
<EditText android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:hint="Enter URL"
/>

<Button
android:id="@+id/btnNavigate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigate"
android:layout_below="@+id/edittext"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
/>

</RelativeLayout
Output:
Ans 2:

<?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">

<Button
android:id="@+id/btnOpenDialer" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Open Dialer"
android:layout_centerInParent="true"
/>

</RelativeLayout>

Java

package com.example.exp18_2;

import androidx.appcompat.app.AppCompatActivity; import android.content.Intent;


import android.view.View;
import android.widget.Button; import android.os.Bundle;

public class MainActivity extends AppCompatActivity { Button btnOenDialer;


@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
btnOenDialer=findViewById(R.id.btnOpenDialer);
btnOenDialer.setOnClickListener(new View.OnClickListener() {
@Override

public void onClick(View v) { Intent intent=new

Intent((Intent.ACTION_DIAL));
startActivity(intent);

});}}
Output
Ans 3)
activity_main.xml
Ans 3)

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:id=”@+id/relativeLayout” android:layout_width=”match_parent” android:layout_height=”match_parent”
tools:context=”.MainActivity”>

<EditText android:id=”@+id/editText”

android:layout_width=”315dp”

android:layout_height=”53dp”

android:layout_centerHorizontal=”true”

android:layout_centerVertical=”true”

android:fontFamily=”@font/poppins_medium”

android:hint=”Enter a number” android:inputType=”number”

android:textSize=”20sp” app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintLeft_toLeftOf=”parent”

app:layout_constraintRight_toRightOf=”parent”

app:layout_constraintTop_toTopOf=”parent”

app:layout_constraintVertical_bias=”0.371

<Button android:id=”@+id/btnFact” android:layout_width=”195dp” android:layout_height=”43dp”


android:layout_marginTop=”84dp”

android:fontFamily=”@font/poppins_medium” android:text=”Factorial” app:layout_constraintLeft_toLeftOf=”parent”


app:layout_constraintRight_toRightOf=”parent” app:layout_constraintTop_toBottomOf=”@+id/editText”/>

</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java

package com.example.exp18_2;
import
androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
public class MainActivity extends AppCompatActivity
{EditText
editText; Button
btnFact;
int fact =
1; int
num=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.editText);
btnFact = findViewById(R.id.btnFact);
btnFact.setOnClickListener(new View.OnClickListener()
{@Override
public void onClick(View v)
{go();
}
});

public void go(){


num =
Integer.parseInt(editText.getText().toString().trim());
for(int i = 1; i <= num; i++){
fact = fact * i;
}

navigate();}
public void navigate(){
Intent intent = new
Intent(MainActivity.this,EmptyActivity.class);
intent.putExtra(“Fact”,fact);
intent.putExtra(“Num”,num);
startActivity(intent);
}
}
activity_empty.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_pare
nt” tools:context=”.EmptyActivity”>
<TextView
android:id=”@+id/textview1”
android:layout_width=”wrap_conten
t”
android:layout_height=”wrap_conte
nt”
android:layout_centerHorizontal=”tr
ue”
android:layout_marginTop=”250dp”
android:fontFamily=”@font/
poppins_medium” android:text=””
android:textColor=”#FFFFFF”
android:textSize=”24sp”/>
<TextView
android:id=”@+id/textview2”
android:layout_width=”wrap_content

android:layout_height=”wrap_content

android:layout_below=”@+id/textvie
w1”
android:layout_centerHorizontal=”tru
e” android:layout_marginTop=”20dp”
android:fontFamily=”@font/
poppins_medium” android:text=””
android:textColor=”#FFFFFF”
android:textSize=”24sp” />
</RelativeLayout>

EmptyActivity.java

package com.example.exp18_2;
import
androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class EmptyActivity extends AppCompatActivity
{TextView
textView1,textView2; int
num,fact;
@Override
protected void onCreate(Bundle savedInstanceState)
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty
); Intent intent = getIntent();
num =
intent.getIntExtra(“Num”,0);
fact =
intent.getIntExtra(“Fact”,0);
textView1 = findViewById(R.id.textview1);
textView2 = findViewById(R.id.textview2);
textView1.setText(“Number = “+ num);
textView2.setText(“Factorial = “+ fact);
}
}
Mobile Application Development(22617)

Maharashtra State Board of Technical Education 137

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy