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

Practical No 18

The document outlines a practical exercise for mobile application development, detailing the XML layout files and Java code for an Android application. It includes components for user input, navigation to a URL, and calculation of factorials. The code demonstrates the use of intents and user interface elements in Android development.

Uploaded by

Huzeefa Pathan
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)
24 views8 pages

Practical No 18

The document outlines a practical exercise for mobile application development, detailing the XML layout files and Java code for an Android application. It includes components for user input, navigation to a URL, and calculation of factorials. The code demonstrates the use of intents and user interface elements in Android development.

Uploaded by

Huzeefa Pathan
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/ 8

Mobile Application Development (22617) Practical No.

18

Practical No.18:

1.

Activity_main.xml
<?xml version=”1.0” encoding=”utf-8”?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jamiapolytechnic.exp181.MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/urlText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:ems="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnNavigate"
android:layout_below="@+id/urlText"
android:text="Navigate"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Maharashtra State Board of Technical Education 1


Mobile Application Development (22617) Practical No. 18

//================================================================
MainActivity.java

package com.jamiapolytechnic.exp181;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText = (EditText)findViewById(R.id.urlText);
Button btn = (Button) findViewById(R.id.btnNavigate);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = editText.getText().toString();

Maharashtra State Board of Technical Education 2


Mobile Application Development (22617) Practical No. 18

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));


startActivity(intent);
}
});
}
}

//================================================================
2.
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.jamiapolytechnic.exp181.MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/urlText"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:ems="10" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnNavigate"
android:layout_below="@+id/urlText"
android:text="Navigate"
android:layout_centerHorizontal="true" />
</RelativeLayout>

//================================================================
MainActivity.java

package com.jamiapolytechnic.exp181;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

Maharashtra State Board of Technical Education 3


Mobile Application Development (22617) Practical No. 18

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editText = (EditText)findViewById(R.id.urlText);
Button btn = (Button) findViewById(R.id.btnNavigate);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url = editText.getText().toString();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
}
}

//================================================================
3.
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
android:text="Enter Number"
/>
<EditText
android:id="@+id/firstNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:inputType="number"
android:ems="10">
</EditText>

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

Maharashtra State Board of Technical Education 4


Mobile Application Development (22617) Practical No. 18

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Factorial" />
</LinearLayout>

//========================================================
result.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/resultView"
android:layout_margin="20dp"/>
</LinearLayout>
//========================================================
MainActivity.java

package com.jamiapolytechnic.exp183;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText firstNum = (EditText)findViewById(R.id.firstNum);

Button btnAdd = (Button)findViewById(R.id.factBtn);


btnAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num1 = Integer.parseInt(firstNum.getText().toString());
Intent intent = new
Intent(MainActivity.this,FactorialActivity.class);

Maharashtra State Board of Technical Education 5


Mobile Application Development (22617) Practical No. 18

intent.putExtra("NUM",num1+"");
startActivity(intent);
}
});
}
}

//========================================================
FactorialActivity.java

package com.jamiapolytechnic.exp183;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

public class FactorialActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
TextView result = (TextView)findViewById(R.id.resultView);
Intent intent = getIntent();
String num_str = (String)intent.getSerializableExtra("NUM");
int num = Integer.parseInt(num_str);
int fact = 1;
for(int i = 1; i <= num; i++) {
fact *= i;
}
result.setText("Factorial: "+fact);
}

//========================================================
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jamiapolytechnic.exp183">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"

Maharashtra State Board of Technical Education 6


Mobile Application Development (22617) Practical No. 18

android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".FactorialActivity" android:label="Factorial">
</activity>

</application>

</manifest>

Maharashtra State Board of Technical Education 7


Mobile Application Development (22617) Practical No. 18

Maharashtra State Board of Technical Education


10

You might also like