0% found this document useful (0 votes)
16 views4 pages

Practical No 18

The document contains code for two Android activities. The first activity defines an interface with an edit text field and button to initiate a web search of the text. The second activity defines an interface with a button that, when clicked, will open the phone dialer and call a specified number. Both activities include the Java code and XML layout code.
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)
16 views4 pages

Practical No 18

The document contains code for two Android activities. The first activity defines an interface with an edit text field and button to initiate a web search of the text. The second activity defines an interface with a button that, when clicked, will open the phone dialer and call a specified number. Both activities include the Java code and XML layout code.
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/ 4

Practical No : 18

Q1:

MainActivity.java:

package com.example.practical_15;

import android.annotation.SuppressLint;

import android.app.SearchManager;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget. EditText;

import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends


AppCompatActivity {

private Button mSearchButton;

private EditText mEnterText;

@SuppressLint("MissingInflatedId")

@Override

protected void onCreate (Bundle savedInstanceState) {

super.onCreate (savedInstanceState);

setContentView(R.layout.activity_main);

mSearchButton = (Button) findViewById(R.id.searchbutton); mEnterText = (EditText)


findViewById(R.id.enteredtext);

mSearchButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String etxt = mEnterText.getText().toString();

if (letxt.isEmpty()) {

Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra (SearchManager.QUERY,


etxt);

startActivity(intent);
{

else

Toast.makeText(MainActivity.t (MainActivity. this, "Not entered

anything", Toast.LENGTH_LONG).show();

} } });

Activity_main.xml :

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

< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout height="match parent"

tools:context=".MainActivity"

android:orientation="vertical">

<EditText

android:layout_width="match_parent"

android:layout height="50dp"

android:hint="Search here"

android:id="@+id/enteredtext"

android:textColor="@color/black" android:layout_marginTop="150dp"

android:layout_marginLeft="35dp"

android:layout_marginRight="35dp"

android:paddingLeft="20dp"

android:background="@drawable/shape" />
<Button

android:layout_width="150dp"

android:layout_height="wrap_content"

android:id="@+id/searchbutton"

android:text="SEARCH"

android:layout_marginTop="30dp"

android:layout_below="@+id/enteredtext" />

</LinearLayout>

Q2:

MainActivity.java

package com.example.practical_15;

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;

public class MainActivity extends AppCompatActivity { Button bl;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

bl=(Button) findViewById(R.id.button);

bl.setOnClickListener(new View.OnClickListener() { @Override

public void onClick(View v) {

Intent intent = new Intent(Intent.ACTION DIAL); intent.setData(Uri.parse("tel:" +


"+917498679710")); startActivity(intent);

});

}}
Activity_main.xml :

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

<LinearLayout

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=".MainActivity"

android:orientation="vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content" android:text="Click to Start te Dialer"

android:textColor="@color/black"

android:textStyle="bold"

android:layout_gravity="center"

android:gravity="center"

android:layout_marginTop="150dp"

android:textSize="20dp"/>

<Button

android:id="@+id/button"

android:background="@drawable/shape"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_marginTop="100dp"

android:gravity="center"

android:layout_gravity="center"

android:text="Start Dialer" />

</LinearLayout>

You might also like