Professional Documents
Culture Documents
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;
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();
}}});
Uri uri=Uri.parse("https://www.youtube.com");
Intent intent=new
Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
}
<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:
<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;
Intent((Intent.ACTION_DIAL));
startActivity(intent);
});}}
Output
Ans 3)
activity_main.xml
Ans 3)
activity_main.xml
<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: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
</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();
}
});
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
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);
}
}