0% found this document useful (0 votes)
13 views19 pages

Practical

practical of cs

Uploaded by

Aries Gaming
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)
13 views19 pages

Practical

practical of cs

Uploaded by

Aries Gaming
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/ 19

PSE/CE/MAD(3170726) Enrollment No.

201120107037

Practical: 1
AIM: 1 Develop an application that uses GUI components, Font and Colors.

Simple application to change font size and color of text view.


1) Open eclipse or android studio and select new android project

2) Give project name and select next

3) Choose the android version. Choose the lowest android version (Android 2.2) and select next

4) Enter the package name. Package name must be two word separated by comma and click finish

5) Go to package explorer in the left hand side. Select our project.


1
PSE/CE/MAD(3170726) Enrollment No.201120107037

6) Go to res folder and select layout. Double click the main.xml file

7) Now you can see the Graphics layout window.

8) Click the main.xml file and type the code below

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

<LinearLayout

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

android:layout_width="fill_parent" android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

2
PSE/CE/MAD(3170726) Enrollment No.201120107037

android:id="@+id/textView1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_margin="20sp"

android:gravity="center"

android:text="HELLO WORLD"

android:textSize="20sp"

android:textStyle="bold" />

<Button

android:id="@+id/button1"

android:layout_width="match_parent"

android:layout_height="wrap_content"
android:gravity="center"

android:text="Change font size"

android:textSize="20sp" />

<Button android:id="@+id/button2"

android:layout_width="match_parent"
3
PSE/CE/MAD(3170726) Enrollment No.201120107037

android:layout_height="wrap_content"

android:gravity="center"

android:text="Change color"

android:textSize="20sp" />

<Button

android:id="@+id/button3"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:text="Change font"

android:textSize="20sp" />

</LinearLayout>

9) Again click the graphics layout tab and screen layout is look like below

4
PSE/CE/MAD(3170726) Enrollment No.201120107037

10) Go to project explorer and select srcfolder.Now select mainactivity.java file and type the
following code.
PROGRAM:-

import android.R; import

android.app.Activity; import

android.graphics.Color; import

android.graphics.Typeface; import

android.os.Bundle; import

android.view.View; import

android.widget.Button; import

android.widget.TextView;

public class AndroidActivity extends Activity

{ float font =24; int i=1;

@Override public void


5
PSE/CE/MAD(3170726) Enrollment No.201120107037

onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

final TextView t1=(TextView)

findViewById(R.id.textView1); Button

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

b1.setOnClickListener(new

View.OnClickListener() {

public void onClick(View view) {

t1.setTextSize(font);

font=font+4; if(font==40)

font=20;

});

Button b2 = (Button)

findViewById(R.id.button2);

6
PSE/CE/MAD(3170726) Enrollment No.201120107037

b2.setOnClickListener(new

View.OnClickListener() {
public void onClick(View view) {

switch(i)

{case 1:

t1.setTextColor(Color.parseColor("#0000FF

")); break; case 2:

t1.setTextColor(Color.parseColor("#00FF00
")); break; case 3:
t1.setTextColor(Color.parseColor("#FF0000"));
break; case 4:
t1.setTextColor(Color.parseColor("#800000")); break;

}i++; if(i==5)
i=1;

});
}}

11) Now go to main.xml and right click .select run as option and select run configuration
7
PSE/CE/MAD(3170726) Enrollment No.201120107037

12) Android output is present in the android emulator as shown in below.

8
PSE/CE/MAD(3170726) Enrollment No.201120107037

Practical: 2
AIM:- DEVELOP AN APPLICATION THAT USES LAYOUT MANAGERS AND EVENT
LISTENERS.
1) Open eclipse or android studio and select new android project

2) Give project name and select next

3) Choose the android version. Choose the lowest android version (Android 2.2) and select next

4) Enter the package name. Package name must be two word separated by comma and click finish

5) Go to package explorer in the left hand side. select our project.

6) Go to res folder and select layout. Double click the main.xml file. Add the code below

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout1" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/linearLayout1
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

9
PSE/CE/MAD(3170726) Enrollment No.201120107037

android:text="ADDITION"
android:textSize="20dp" >
</TextView>
</LinearLayout><LinearLayou
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/linearLayout1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTER NO 1" >
</TextView><EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.20"
android:id="@+id/edittext1"
android:inputType="number">
</EditText>
</LinearLayout><LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"

10
PSE/CE/MAD(3170726) Enrollment No.201120107037

android:layout_below="@+id/linearLayout2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENTER NO 2" >
</TextView><EditText

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

android:layout_weight="0.20"

android:id="@+id/edittext2"

android:inputType="number">

</EditText>

</LinearLayout><LinearLayout

android:id="@+id/linearLayout4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentRight="true"

android:layout_below="@+id/linearLayout3" >
11
PSE/CE/MAD(3170726) Enrollment No.201120107037

<Button

android:layout_width="wrap_content"

android:id="@+id/button1"

android:layout_height="wrap_content"

android:text="Addition
android:layout_weight="0.50" />
<Button
android:layout_width="wrap_content"
android:id="@+id/button3"
android:layout_height="wrap_content"
android:text="subtraction"
android:layout_weight="0.50" />
<Button
android:layout_width="wrap_content"
android:id="@+id/button2"
android:layout_height="wrap_content
android:text="CLEAR"
android:layout_weight="0.50" />
</LinearLayout>
<View android:layout_height="2px"
android:layout_width="fill_parent"
android:layout_below="@+id/linearLayout4"
android:background="#DDFFDD"/>

12
PSE/CE/MAD(3170726) Enrollment No.201120107037

</RelativeLayout>

7) Now select mainactivity.java file and type the following code.


package layout.ne;

import android.app.Activity; import


android.os.Bundle; import
android.view.View; import
android.view.View.OnClickListener; import
android.widget.Button; import
android.widget.EditText; import
android.widget.Toast;

public class LAYOUTActivity


extends Activity {
/** Called when the activity is first created. */ EditText
txtData1,txtData2; float num1,num2,result1,result2;
@Override
public void onCreate(Bundl
savedInstanceState) {
super.onCreate(savedInstanceSt
ate);
setContentView(R.layout.main);
Button add = (Button)
findViewById(R.id.button1);
add.setOnClickListener(new
OnClickListener() { void onClick(View v) { try

txtData1 = (EditText) findViewById(R.id.edittext1); txtData2 = (EditText)


findViewById(R.id.edittext2); Float.parseFloat(txtData1.getText().toString());
Float.parseFloat(txtData2.getText().toString()); result2=num1-num2
13
PSE/CE/MAD(3170726) Enrollment No.201120107037

Toast.makeText(getBaseContext(),"ANSWER:"+result2,Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
Button clear = (Button) findViewById(R.id.button2);
clear.setOnClickListener(new OnClickListener() {

public void onClick(View v) {


try
{txtData1.setText("")txtData2.setText("");

8) Now go to main.xml and right click .select run as option and select run configuration
9) Android output is present in the android emulator as shown in below

14
PSE/CE/MAD(3170726) Enrollment No.201120107037

Practical :3
Aim : Create Activities & implement following
1. Implicit intent
2. Explicit Intent
3.StartActivityForResult

activity_main.xml

<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
adroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"

15
PSE/CE/MAD(3170726) Enrollment No.201120107037

android:layout_alignParentTop="true"
android:layout_marginTop="48dp"
android:text="Default Message" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp"
android:text="GetMessage" />

</RelativeLayout>
second_main.xml

<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SecondActivity" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
16
PSE/CE/MAD(3170726) Enrollment No.201120107037

android:layout_alignParentTop="true"
android:layout_marginTop="61dp"
android:layout_toRightOf="@+id/textView1
android:ems="10" /
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true" android:text="Enter
Message:" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:text="Submit" />
</RelativeLayout>

MainActivity.java

package com.javatpoint.startactivityforresult;
import android.os.Bundle;
import android.app.Activity;
17
PSE/CE/MAD(3170726) Enrollment No.201120107037

import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView textView1;
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView1=(TextView)findViewById(R.id.textView1);
button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent=new Intent(MainActivity.this,SecondActivity.class);


startActivityForResult(intent, 2);// Activity is started with requestCode 2

}
});
}

18
PSE/CE/MAD(3170726) Enrollment No.201120107037

19

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy