Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

XML FILE:- JAVA FILE:-

<?xml version="1.0" encoding="utf-8"?> package com.example.myapplication;


<LinearLayout xmlns:android="http://schemas. import androidx.appcompat.app.AppCompatActivity;
android.com/apk/res/android" import android.content.Intent;
xmlns:tools="http://schemas. import android.net.Uri;
android.com/tools" import android.os.Bundle;
android:layout_width="match_parent" import android.view.View;
android:layout_height="match_parent" import android.widget.*;
android:orientation="vertical" public class MainActivity extends AppCompatActivity {
tools:context=".MainActivity"> @Override
<EditText protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_main);
android:id="@+id/e1"/> Button b1=findViewById(R.id.b);
<Button EditText e1=findViewById(R.id.e1);
android:layout_width="wrap_content" b1.setOnClickListener(new View.OnClickListener() {
android:layout_height="wrap_content" @Override
android:text="Navigate" public void onClick(View v) {
android:id="@+id/b" String s=e1.getText().toString();
/> Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse(s));
</LinearLayout> startActivity(i);
}
});
}
}
XML FILE:- JAVA FILE:-
<?xml version="1.0" encoding="utf-8"?> package com.example.myapplication;
<LinearLayout xmlns:android="http://schemas. import androidx.appcompat.app.AppCompatActivity;
android.com/apk/res/android" import android.content.Intent;
xmlns:tools="http://schemas import android.net.Uri;
.android.com/tools" import android.os.Bundle;
android:layout_width="match_parent" import android.view.View;
android:layout_height="match_parent" import android.widget.*;
android:orientation="vertical" public class MainActivity extends AppCompatActivity {
tools:context=".MainActivity"> @Override
<Button protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" super.onCreate(savedInstanceState);
android:layout_height="wrap_content" setContentView(R.layout.activity_main);
android:text="Go to" Button b1=findViewById(R.id.b);
android:id="@+id/b" b1.setOnClickListener(new View.OnClickListener() {
/> @Override
</LinearLayout> public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_DIAL,
Uri.parse("tel: +919325025671"));
startActivity(i);
}
});
}
}
XML FILE: - JAVA FILE: -
Activity_main.xml package com.example.myapplication;
<?xml version="1.0" encoding="utf-8"?> import androidx.appcompat.app.AppCompatActivity;
<LinearLayout xmlns:android="http://schemas import android.content.Intent;
.android.com/apk/res/android" import android.os.Bundle;
xmlns:app="http://schemas. import android.view.View;
android.com/apk/res-auto" import android.widget.*;
xmlns:tools="http://schemas.android.com/tools" public class MainActivity extends AppCompatActivity {
android:layout_width="match_parent" @Override
android:layout_height="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:orientation="vertical" super.onCreate(savedInstanceState);
tools:context=".MainActivity"> setContentView(R.layout.activity_main);
<EditText Button b=findViewById(R.id.btn);
android:layout_width="wrap_content" final EditText et=findViewById(R.id.e);
android:layout_height="wrap_content" b.setOnClickListener(new View.OnClickListener()
android:id="@+id/e"/> {@Override
<Button public void onClick(View v) {
android:layout_width="wrap_content" int n= Integer.parseInt(et.getText().toString());
android:layout_height="wrap_content" int fact=1;
android:text="Calculate" for (int i = 1; i <= n; ++i) {
android:id="@+id/btn"/> fact=fact*i;
</LinearLayout> }
Intent i=new
Res.xml Intent(MainActivity.this,result.class);
<LinearLayout xmlns:android="http://schemas.a i.putExtra("factorial", String.valueOf(fact));
ndroid.com/apk/res/android" startActivity(i); }
android:layout_width="match_parent" });
xmlns:tools="http://schemas.android.com/tools" }
tools:context=".result" }
android:layout_height="match_parent">
<TextView Result.java
android:layout_width="wrap_content" package com.example.myapplication;
android:layout_height="wrap_content" import androidx.appcompat.app.AppCompatActivity;
android:id="@+id/t1"/> import android.os.Bundle;
</LinearLayout> import android.widget.*;
public class result extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.res);
TextView t = findViewById(R.id.t1);
String s = getIntent().getStringExtra("factorial");
t.setText(s);
}
}

You might also like