0% found this document useful (0 votes)
15 views3 pages

EXPLICIT INTENT

Uploaded by

tenor75805
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)
15 views3 pages

EXPLICIT INTENT

Uploaded by

tenor75805
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/ 3

EXPLICIT INTENT

1.XML FILE

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


<LinearLayout 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:layout_width="103dp"
android:layout_height="168dp"
android:layout_gravity="center_horizontal"
android:text="Finding Factorial"
android:textSize="40sp"
android:textStyle="bold" />

<EditText
android:id="@+id/fact"
android:layout_width="99dp"
android:layout_height="240dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="100dp"
android:hint="Enter a Number"
android:textSize="30sp" />

<Button
android:id="@+id/showOP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="100dp"
android:backgroundTint="#F4A84C"

android:text="Calculate"
android:textSize="25sp" />
</LinearLayout>

2.XML file

<?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">
<TextView
android:id="@+id/tv1"
android:layout_width="133dp"
android:layout_height="85dp"
android:layout_marginEnd="108dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.396" />

</androidx.constraintlayout.widget.ConstraintLayout>

1.java file

package com.example.explintent;

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 fact;
Button showOP;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fact=findViewById(R.id.fact);
showOP=findViewById(R.id.showOP);
showOP.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View view)
{
Intent i= new Intent(MainActivity.this,OutputAct.class);
i.putExtra("number",fact.getText().toString());
startActivity(i);
}
});

}
2 Java file

package com.example.explintent;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.TextView;

public class OutputAct extends AppCompatActivity


{

TextView tv1;
private Bundle savedInstanceState;

@SuppressLint("MissingInflatedId")
@Override
public void onCreate(Bundle SavedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_output);
Bundle b= getIntent().getExtras();
int no=Integer.parseInt(b.getString("number"));
long f=1;
for(int i=no;i>0;i--)
{
f=f+i;
}
tv1=findViewById(R.id.showOP);
tv1.setText("factorial of "+no+"is"+f);
}

You might also like