0% found this document useful (0 votes)
5 views8 pages

Amazon MAD18 App Development Guide

The document contains code snippets for Android applications, including XML layout files and Java activity classes. It demonstrates how to create user interfaces with buttons and text fields, handle user input, and navigate between activities. The applications include functionalities like opening a URL in a browser and calculating the factorial of a number.
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)
5 views8 pages

Amazon MAD18 App Development Guide

The document contains code snippets for Android applications, including XML layout files and Java activity classes. It demonstrates how to create user interfaces with buttons and text fields, handle user input, and navigate between activities. The applications include functionalities like opening a URL in a browser and calculating the factorial of a number.
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

Exp 18.

1
android:textSize="16sp"
Main_Activity.xml android:textStyle="bold"
android:textColor="#FFFFFF"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_below="@id/btnNavigate"
xmlns:android="[Link] android:layout_centerHorizontal="true"
/apk/res/android" android:layout_marginTop="20dp"
/>
xmlns:app="[Link]
/res-auto" </RelativeLayout>

xmlns:tools="[Link] ols" [Link]


android:layout_width="match_parent"
android:layout_height="match_parent" package [Link].exp18; import
tools:context=".MainActivity"> [Link]
y;
<EditText android:id="@+id/edittext" import [Link]; import
android:layout_width="match_parent" [Link];
android:layout_height="wrap_content"
android:layout_centerInParent="true" import [Link]; import
android:hint="Enter URL" [Link]; import
/> [Link]; import
[Link];
<Button
android:id="@+id/btnNavigate" public class MainActivity extends
android:layout_width="wrap_content" AppCompatActivity {
android:layout_height="wrap_content" EditText editText;
android:text="Navigate" Button btnNavigate;
android:layout_below="@id/edittext" String text;
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp" @Override
/> protected void onCreate(Bundle
savedInstanceState) {
<TextView android:id="@+id/labelvd" [Link](savedInstanceState);
android:layout_width="wrap_content"
android:layout_height="wrap_content" setContentView([Link].activity_main);
btnNavigate =
findViewById([Link]);
[Link](new
[Link]() {
@Override
public void onClick(View v) {
editText =
findViewById([Link]);
text =
[Link]().toString().trim();
if
([Link]("[Link]")) {
go();

}
}
});
}

public void go() { Uri


uri =
[Link]("[Link] Intent
intent = new
Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}

Output:
Exp 18.2
[Link]
Main_Activity.xml
package [Link].exp18_1; import
[Link] y;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout import [Link]; import
xmlns:android="[Link] [Link]; import
/apk/res/android" [Link]; import
[Link];
xmlns:app="[Link]
/res-auto" public class MainActivity extends
AppCompatActivity {
xmlns:tools="[Link] ols" Button btnOenDialer; @Override
android:layout_width="match_parent" protected void onCreate(Bundle
android:layout_height="match_parent" savedInstanceState) {
tools:context=".MainActivity"> [Link](savedInstanceState);

<Button setContentView([Link].activity_main);
android:id="@+id/btnOpenDialer"
android:layout_width="wrap_content" btnOenDialer=findViewById([Link]
android:layout_height="wrap_content" Dialer);
android:text="Open Dialer" [Link](new
android:layout_centerInParent="true"/> [Link]() {
@Override
<TextView public void
android:id="@+id/tvPerformedBy" onClick(View v) {
android:layout_width="wrap_content" Intent
android:layout_height="wrap_content" intent=new Intent((Intent.ACTION_DIAL));
android:text="Performed by Madhura
Pawar" startActivity(intent);
android:textSize="16sp" }
android:textStyle="bold" }

android:layout_below="@id/btnOpenDialer " );
android:layout_centerHorizontal="true" }
android:layout_marginTop="20dp"/>

</RelativeLayout>
}

Output:

Performed By Saish Gurav

18.2
android:layout_width="match_parent"
Main_Activity.xml

<?xml version="1.0" encoding="utf-8"?> android:layout_height="match_parent"


<RelativeLayout tools:context=".MainActivity">
xmlns:android="[Link]
/apk/res/android" <EditText
android:id="@+id/editText"
xmlns:app="[Link] android:layout_width="match_parent"
/res-auto" android:layout_height="wrap_content"
android:layout_centerInParent="true" import [Link]; import
android:hint="Enter a number"
[Link]; import
android:inputType="number"/>
[Link]; import
<Button [Link];
android:id="@+id/btnFact"
android:layout_width="wrap_content"
android:layout_height="wrap_content" public class MainActivity extends
android:text="Factorial"
AppCompatActivity {
android:layout_below="@id/editText"
android:layout_marginTop="40dp"
EditText editText; Button
android:layout_centerHorizontal="true"/>
btnFact;
<TextView
android:id="@+id/tvPerformedBy"
@Override
android:layout_width="wrap_content"
android:layout_height="wrap_content" protected void onCreate(Bundle
android:text="Performed by Saish savedInstanceState) {
Gurav” [Link](savedInstanceState);
android:textSize="16sp"
android:textStyle="bold"
android:layout_below="@id/btnFact" setContentView([Link].activity_main);
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>
editText =
findViewById([Link]);
</RelativeLayout>
btnFact = findViewById([Link]);
[Link]
[Link](new
[Link]() {
@Override
package [Link].exp18_3;
public void onClick(View v) {

import go();
[Link] y; }
import [Link]; });
}
public void go() { <application android:allowBackup="true"
int fact = 1; android:icon="@mipmap/ic_launcher"
int num = android:label="@string/app_name"
[Link]([Link]().toString()
.trim());
android:roundIcon="@mipmap/ic_launcher
_round"
for (int i = 1; i <= num; i++) { fact *= android:supportsRtl="true"
i;
} android:theme="@style/Theme.Exp18_3">

navigate(num, fact); <activity android:name=".EmptyActivity"/>

}
<!-- Add android:exported="true" -->
<activity
public void navigate(int num, int fact) { Intent
android:name=".MainActivity"
intent = new
android:exported="true">
Intent([Link], [Link]);
<intent-filter>
[Link]("Fact", fact);
<action
[Link]("Num", num);
android:name="[Link] "
startActivity(intent); />
} <category
android:name="[Link]
} NCHER" />
</intent-filter>
[Link] </activity>
<?xml version="1.0" encoding="utf-8"?>
<manifest </application>
xmlns:android="[Link]
/apk/res/android"
package="[Link].exp18_3">
</manifest> textView1 =
findViewById([Link].textview1);
textView2 =
[Link] findViewById([Link].textview2);
package [Link].exp18_3;

[Link]("Number = "+ num);


import [Link]("Factorial = "+ fact);
[Link] y;
}}

import [Link];
Empty_activity.xml
import [Link]; import
[Link];
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
public class EmptyActivity extends xmlns:android="[Link]
AppCompatActivity { /apk/res/android"

TextView textView1,textView2; xmlns:app="[Link]


/res-auto"
int num,fact;
@Override xmlns:tools="[Link] ols"
protected void onCreate(Bundle android:layout_width="match_parent"
savedInstanceState) {
android:layout_height="match_parent"
[Link](savedInstanceState);
tools:context=".EmptyActivity">

setContentView([Link].empty_activity);
<TextView
android:id="@+id/textview1"
Intent intent = getIntent();
num = [Link]("Num",0); fact = android:layout_width="wrap_content"
android:layout_height="wrap_content"
[Link]("Fact",0);
android:text=""
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
/>

<TextView android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
Performed By Saish Gurav
android:layout_below="@+id/textview1"
/>
</RelativeLayout>
Output:

Performed By Saish Gurav

You might also like