You are on page 1of 39

Mobile Application Practical 19CS1K2165

1. Creating “Hello world” Application.

Procedure:
Step 1: Open File menu→New→New project.

Step 2: Under configuration your new project, fill in the fields. Fill the application name where
the first letter should start with caps then other fields keep remain same as it is. Give the name
for your application click next.

Step 3: By default make phone and tablet selected and set the minimum SDK as API 16 and 4.1
(Jelly Bean).

Step 4: Select blank activity from the list of activity displayed. Click Next.

Step 5: Click next with the default activity name i.e. Main Activity.

Step 6: Open Content_main.xml file and look for the attribute android:text=”Hello World”.

Step 7: Start your emulator and make it run(Virtual Device).

Step 8: Click on the run button.

Step 9: Open the menu option in the emulator.

VI Semester BCA 1 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 2 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

2.Create an Application that displays message based on the screen orientation.

Procedure:
Step1: Create a new project and give appropriate application name.

Step2: Open MainActivity.java file and import the following namespace.

MainActivity.java

import android.widget.Toast;

Step3: Open AndroidManifest.xml file and add an attribute under activity.

android:configChanges="orientation|screenSize"

Step4: Write the function in MainActivity.java say onConfigurationChange.

@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE)
{
Toast toast =Toast.makeText(this,"this is landscape view",Toast.LENGTH_LONG);
toast.show();
}
else if (newConfig.orientation==Configuration.ORIENTATION_PORTRAIT)
{
Toast toast = Toast.makeText(this, "this is portrait view", Toast.LENGTH_LONG);
toast.show();
}

Step5: Start your Emulator and Run the application.

Step6: Use ctrl+F11 key to see the orientation changes of the screen.

VI Semester BCA 3 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 4 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

3. Create an application that displays custom designed Opening Screen.

Procedure:
Step 1: Open the new project and give appropriate application name.

Step 2: Go to the project explore window.

Step 3: Copy content main.xml and create new file splashh.xml.

Step 4: Copy a image into a drawable folder .png.

Step 5: Open splashh.xml file in design tab, drag and drop one image view control.

Step 6: Go to the text tab of splashh.xml file and delete a line

tools:showIn=”@layout/activity_main”/>

Step 7: Go to project explorer window and create splash.java file under java folder.

Step 8: Import the following namespaces and type the following code:

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class splash extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
final ImageView vi=(ImageView)findViewById(R.id.imageView);
final Animation an= AnimationUtils.loadAnimation(getBaseContext(),R.anim.rotate);
final Animation
an2=AnimationUtils.loadAnimation(getBaseContext(),R.anim.abc_fade_out);
vi.startAnimation(an);
an.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {

VI Semester BCA 5 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

@Override
public void onAnimationEnd(Animation animation) {
finish();
Intent i=new Intent(getBaseContext(),MainActivity.class);
startActivity(i);
}

@Override
public void onAnimationRepeat(Animation animation) {

}
});
}
}

Step 9: Create a new folder say “Anim” under resources, create rotate.xml file inside anim folder

Step 10: Open rotate.xml file and add the following code.

<rotate
android:duration="5000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"></rotate>

Step 11: In manifest.xml file add the following code.

<activity
android:name=".splash"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>

VI Semester BCA 6 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 7 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

VI Semester BCA 8 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

4. Create menu in Application.

Procedure:
Step1: Create a new project and give appropriate application name.

Step2: Open Project Explorer window and open the folder say menu.

Step3: The menu folder has a default Menu resource file say menu_main.xml.

Step4: Open a menu_main.xml file which has a default menu built inside it. Include the <item>
tag and its attributes after closing tools tag.

menu_main.xml

<item android:id="@+id/item1"
android:title="item1"/>
<item android:id="@+id/item2"
android:title="item2"/>
<item android:id="@+id/item3"
android:title="item3"/>

Step5: Open MainActivity.java file and Import android.widget.Toast; look for the function
onOptionsItemSelected.

Step6: Remove all the lines in the onOptionsItemSelected function and replace the code.

MainActivity.java
switch (item.getItemId())
{
case R.id.item1:
Toast.makeText(this, "item1 selected", Toast.LENGTH_LONG).show();
return true;
case R.id.item2:
Toast.makeText(this, "item2 selected", Toast.LENGTH_LONG).show();
return true;
case R.id.item3:
Toast.makeText(this, "item3 selected", Toast.LENGTH_LONG).show();
return true;
default:
return super.onOptionsItemSelected(item);
}

Step7: Start your Emulator and Run the application.

VI Semester BCA 9 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 10 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

5. Play an audio, based on the user event.

Procedure:
Step1: Create a new project and give appropriate application name.

Step2: Open Project Explorer window and right click the resource folder and create a new folder
by the name raw.

Step3: Copy any two .mp3 files into the raw folder by renaming it has A.mp3 and B.mp3.

Step4: Open content_main.xml file and place two buttons in the layout.

Step5: Open text tab of content_main.xml file and rename the text property of Button1 and
Button2 as "Audio 1" and "Audio 2".

Step6: Open MainActivity.java file and import the following namespaces.

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.view.View.OnClickListener;
import android.widget.Button;

Step7: In MainActivity.java file add the keyword implements onClickListener in the public
class.

public class MainActivity extends AppCompatActivity implements OnClickListener

Step8: Declare a variable in MainActivity.java file after public class.

private MediaPlayer mp;

Step9: In onCreate() function after setContentView include the following code.

setVolumeControlStream(AudioManager.STREAM_MUSIC);
Button button1 = (Button) findViewById(R.id.button);
Button button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(this);
button2.setOnClickListener(this);

Step10: After onCreate() function include the following code.

public void onClick(View v)


{
int resId;
switch (v.getId())
{

VI Semester BCA 11 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

case R.id.button:
resId=R.raw.a;
break;
case R.id.button2:
resId=R.raw.b;
break;
default:
resId=R.raw.a;
break;
}
if (mp!=null)
{
mp.release();
}
mp=MediaPlayer.create(this,resId);
mp.start();
}

Step11: After onCreateOptionMenu() function include the following code.

protected void onDestroy()


{
if (null != mp) {
mp.release();
}
super.onDestroy();
}

Step12: Start your Emulator and Run the application.

VI Semester BCA 12 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 13 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

6. Read/ write the Local data.

Procedure:
Step1: Create a new project and give appropriate application name.

Step2: Open content_main.xml file text tab and add the line in <RelativeLayout> tag as last
attribute.

content_main.xml or activity_main.xml

tools:context="{RelativePackage}.${activityClass}"

Step3: Open content_main.xml file design tab and place a TextView control, EditText control
and two Button controls.

Step4: Change the TextView control properties of


text="Android Read and Write text from file"
textColor="#fff"

Step5: drag and drop EditText control in content_main.xml file .

Step6: Change the button1 property as:


android:layout_below="@+id/button"
android:text="Write Text into file"
android:onClick="WriteBtn"

Step7: Change the button2 property as:


android:layout_below="@+id/button1"
android:text="Read text from file"
android:onClick="ReadBtn"

Step8: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import android.widget.EditText;
import android.widget.Toast;

Step9: Declare the variables in MainActivity.java file after the public class.

VI Semester BCA 14 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

EditText textmsg;
static final int READ_BLOCK_SIZE=100;

Step10: In onCreate() function after setContentView include the following line.

textmsg=(EditText)findViewById(R.id.editText1);

Step11: Delete all other functions.

Step12: After onCreate() function include the following code.

public void WriteBtn(View v)


{
try {
FileOutputStream fileout=openFileOutput("mytextfile.txt",MODE_PRIVATE);
OutputStreamWriter outputWriter=new OutputStreamWriter(fileout);
outputWriter.write(textmsg.getText().toString());
outputWriter.close();
Toast.makeText(getBaseContext(),"File Saved
Successfully!",Toast.LENGTH_SHORT).show();
}catch (Exception e)
{
e.printStackTrace();
}
}
public void ReadBtn(View v)
{
try{
FileInputStream filein=openFileInput("mytextfile.txt");
InputStreamReader inputRead=new InputStreamReader(filein);
char[] inputBuffer=new char[READ_BLOCK_SIZE];
String s="";
int charRead;

while ((charRead=inputRead.read(inputBuffer))>0)
{
String readstring=String.copyValueOf(inputBuffer,0,charRead);
s+=readstring;
inputRead.close();
Toast.makeText(getBaseContext(),s,Toast.LENGTH_SHORT).show();
}
}catch (Exception e)
{
e.printStackTrace();
}

VI Semester BCA 15 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

}
}
Step13: Start your Emulator and Run the application.
OUTPUT :

VI Semester BCA 16 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

7. Create an Android program for addition of two numbers using editview


control and button.

Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project

Step 2: Drag and drop the following views in Content_Main.XML file


 Three Text View
 Two Plain Text
 Button

Step 3: Rename the text of the Text View controls as “Enter First Number” and “Enter Second
Number”

Step 4: Rename the text of Button as “Calculate”

Step 5: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

Step 6: Declare the following variables in the class MainActivity.


EditText number1;
EditText number2;
Button Add_button;
TextView result;
int ans=0;

Step 7: In onCreate() function after setContentView add the code.

number1=(EditText) findViewById(R.id.editText);
number2=(EditText) findViewById(R.id.editText2);
Add_button=(Button) findViewById(R.id.button);
result=(TextView) findViewById(R.id.textView);
Add_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

VI Semester BCA 17 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

double num1=Double.parseDouble(number1.getText().toString());
double num2=Double.parseDouble(number2.getText().toString());
double sum=num1+num2;
result.setText(Double.toString(sum));
}
});

Step 8: Start your Emulator and Run the application.

VI Semester BCA 18 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 19 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

8. Create an Android program for demonstrating the usage of a progressbar


for downloading music.

Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project

Step 2: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.view.View;
import android.widget.Button;

Step 3: Add a Button to activity_main.xml and add a button property.


android:text=”Download”
android:onClick=”download”

Step 4: Declare the variables in public class MainActivity.


Button b1;
private ProgressDialog progress;

Step 5: In onCreate() function after setContentView add the code.


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

Step 6: After onCreate() function include the following code.

public void download(View view){


progress=new ProgressDialog(this);
progress.setMessage("Download Music");
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progress.setIndeterminate(true);
progress.setProgress(0);
progress.show();
final int totalProgressTime=100;
final Thread t=new Thread(){
@Override
public void run(){
int jumpTime=0;
while (jumpTime<totalProgressTime){
try{

VI Semester BCA 20 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

sleep(200);
jumpTime +=5;
progress.setProgress(jumpTime);
}catch (InterruptedException e){
e.printStackTrace();
}
}
}
};
t.start();
}

Step 7: Start your Emulator and Run the application.

VI Semester BCA 21 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 22 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

9. Create a Tiles based application using an Android IDE.

Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project
Step 2: Prepare your image which you want to show in grid layout and place them in
res→drawable folder

Step 3: Drag and drop the following views in Content_Main.XML file


 Text View
 Grid View

Step 4: Create a new class by the name “imageAdapter.java”


(Right Click)app→java folder(Right Click)→new→class file and name it
as “imageAdapter.java”

Step 5: Extend your ImageAdapter.java class from BaseAdapter and fill with following code

Import the following namespaces:

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

Type the following code inside class file:

public class ImageAdapter extends BaseAdapter {


private Context mContext;
public Integer[]
mThumbIds={R.drawable.i2,R.drawable.i3,R.drawable.one,R.drawable.i45,R.drawable.i6,R.dra
wable.i7,R.drawable.one,R.drawable.i7,R.drawable.i6,R.drawable.one,R.drawable.i6,R.drawable
.i45};

public ImageAdapter(Context c){


mContext=c;
}
@Override

VI Semester BCA 23 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

public int getCount(){


return mThumbIds.length;
}
@Override
public Object getItem(int position){
return mThumbIds[position];
}
@Override
public long getItemId(int position){
return 0;
}
@Override
public View getView(int position,View convertView,ViewGroup parent){
ImageView imageView;
if (convertView==null){
imageView=new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85,85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
}
else {
imageView=(ImageView)convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}

Step 6: In MainActivity.java add the following code

Import the following namespaces:

import android.widget.GridView;

After setContentView inside onCreate function add the following code:

GridView gridView=(GridView)findViewById(R.id.gridView);
gridView.setAdapter(new ImageAdapter(this));

Step7: Start your Emulator and Run the application.

VI Semester BCA 24 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 25 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

10. Developing Search application.

Procedure:
Step1: Create a new project and give appropriate application name.

Step2: Create required files needed to generate a ListView and EditText.

Open content_main.xml file or activity_main.xml file and drag and drop ListView control and
PlainText control. Change the attributes values of EditText has given in the following code.

activity_main.xml

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/inputSearch"
android:ems="10"
android:hint="Search Products"
android:inputType="textVisiblePassword"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/textView" />

Step3: Change the value of ListView id attribute as "list_view".

Step4: Create a xml file in res/layout folder and name it as list_item.xml.


Drag and drop a TextView control and change the id as "product_name".

Step5: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.text.Editable;
import android.widget.ArrayAdapter;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.ListView;

Step6: Declare the variables in MainActivity.java before the onCreate function.

VI Semester BCA 26 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

MainActivity.java

private ListView lv;


ArrayAdapter <String> adapter;
EditText inputSearch;
ArrayList <HashMap<String,String>> productList;

Step7: After setContentView in onCreate function include the following code.

MainActivity.java

String products[]={"Bangalore","Mangalore","Karnataka","Chennai","Kerala"};
lv=(ListView)findViewById(R.id.list_view);
inputSearch=(EditText)findViewById(R.id.inputSearch);

adapter=new ArrayAdapter<String>(this,R.layout.list_item,R.id.product_name,products);
lv.setAdapter(adapter);
}

inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int i, int i1, int i2)
{
MainActivity.this.adapter.getFilter().filter(cs);
}

Step8: Open AndroidManifest.xml file to hide the keyboard on loading activity.


Place the code in <activity> before <intent-filter> opening tag starts.

AndroidManifest,xml

android:windowSoftInputMode="stateHidden"

Step9: Start your Emulator and Run the application.

VI Semester BCA 27 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 28 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

11. Create an Android program to draw a circle.

Procedure:
Step 1: Create a new Android Application and give appropriate name
File→New →New Project

Step 2: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.view.View;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;

Step 3: Change the following code in setContentView of onCreate function.


setContentView(new myView(this));

Step 4: Declare a class myView that extends View.

public class myView extends View {


public myView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int x = getWidth();
int y = getHeight();
int radius;
radius = 100;
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.WHITE);
canvas.drawPaint(paint);
paint.setColor(Color.parseColor("#53fbff"));
canvas.drawCircle(x / 2, y / 2, radius, paint);
}
}

Step 5: Start your Emulator and Run the application.

VI Semester BCA 29 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 30 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

12. Create an Android program for different type of animation from the menu
and the selected animation.

Procedure:
Step 1: Create a new project and give appropriate application name.

Step 2: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;

Step 3: After onCreate() function write the function for fade in and blink animation.

public void fade(View view){


ImageView image=(ImageView)findViewById(R.id.imageView);
Animation animation1=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade);
image.startAnimation(animation1);
}

public void blink(View view){


ImageView image=(ImageView)findViewById(R.id.imageView);
Animation
animation1=AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blink);
image.startAnimation(animation1);
}

Step 4: Drag and drop two Buttons and the Image View control in activity_main.xml and paste a
pic in drawable folder.

Step 5: Change the Button text property as “Fade” for button1 and “Blink” for button2. For the
Image View control give the source of the image.

Step 6: Create an ‘anim’ folder, and inside ‘anim’ folder create xml file by the name
‘myanimation.xml’.

Step 7: In myanimation.xml add the following code.


<set>
<scale
android:fromXScale="0.5"

VI Semester BCA 31 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

android:fromYScale="0.5"
android:toXScale="3.0"
android:toYScale="3.0"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%">
</scale>
<scale
android:startOffset="5000"
android:fromXScale="0.5"
android:fromYScale="0.5"
android:toXScale="3.0"
android:toYScale="3.0"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%">
</scale>
</set>

Step 8: Create a file under anim folder as ‘fade.xml’.


<set>
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="2000">
</alpha>
<alpha
android:startOffset="2000"
android:fromAlpha="1"
android:toAlpha="0"
android:duration="2000">
</alpha>
</set>

Step 9: Create a file under anim folder as ‘blink.xml’.


<set>
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="600"
android:repeatMode="reverse"
android:repeatCount="infinite"/>
</set>

Step 10: Start your Emulator and Run the application.

VI Semester BCA 32 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 33 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

13. Android program to demonstrate the usage of activity life cycle.


Procedure:
Step 1: Create a new project and give appropriate application name.
Step 2: Open MainActivity.java file and import the following namespaces.

MainActivity.java
import android.util.Log;

Step 3:After setContentView in onCreate function write the log file for displaying the message.
Log.d("LifeCycle","onCreate Invoked");

Step 4: Implement all the stages one by one.

protected void onStart(){


super.onStart();
Log.d("LifeCycle", "onStart Invoked");
}
@Override
protected void onResume(){
super.onResume();
Log.d("LifeCycle", "onResume Invoked");
}
@Override
protected void onPause(){
super.onPause();
Log.d("LifeCycle", "onPause Invoked");
}
@Override
protected void onStop(){
super.onStop();
Log.d("LifeCycle", "onStop Invoked");
}
@Override
protected void onRestart(){
super.onRestart();
Log.d("LifeCycle", "onRestart Invoked");
}
@Override
protected void onDestroy(){
super.onDestroy();
Log.d("LifeCycle", "onDestroy Invoked");
}

Step 5: Start your Emulator and Run the application.

VI Semester BCA 34 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 35 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

14.Android program to demonstrate touch listener.


Procedure:
Step 1: Create a new project and give appropriate application name.
Step 2: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.view.View;
import android.view.MotionEvent;
import android.widget.Toast;
import android.widget.TextView;

Step 3: In MainActivity.java file add the keyword implements view.onTouchListener in the


public class.

public class MainActivity extends AppCompatActivity implements View.OnTouchListener

Step 4: Declare the variables under public class.

int no1=15;
int no2=10;
int s;

Step 5: In onCreate function after setContentView add the following code.

TextView tv=(TextView) findViewById(R.id.textView);


tv.setOnTouchListener(this);

Step 6: After onCreate function add the codes.

public boolean onTouch(View v, MotionEvent event) {


Toast.makeText(getBaseContext(),"Touch Event On View",Toast.LENGTH_LONG).show();
return false;
}
@Override
public boolean onTouchEvent(MotionEvent e){
final float x=e.getX();
final float y=e.getY();
Toast.makeText(getBaseContext(),"Coordinates X:"+x+" Y:
"+y,Toast.LENGTH_LONG).show();
return true;
}

Step 7: Start your Emulator and Run the application.

VI Semester BCA 36 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 37 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

15. Java Android program to demonstrate Implicit Intent.


Procedure:
Step 1: Create a new project and give appropriate application name.
Step 2: Open MainActivity.java file and import the following namespaces.

MainActivity.java

import android.view.View;
import android.widget.Button;
import android.net.Uri;
import android.content.Intent;
import android.widget.EditText;

Step 3: Open activity_main.xml file and place your edittext control and button. Change the name
of the button to “Click Here” through text property.

Step 4: In onCreate function declare the variables for textbox and the button.

final EditText editText1=(EditText)findViewById(R.id.editText);


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

Step 5: Declare the listener class through onClick event.

button.setOnClickListener(new View.OnClickListener() {
});

Step 6: Start your Emulator and Run the application.

VI Semester BCA 38 Kristu Jayanti College


Mobile Application Practical 19CS1K2165

OUTPUT :

VI Semester BCA 39 Kristu Jayanti College

You might also like