0% found this document useful (0 votes)
101 views

Android Application To Display Hello World Activity - Helloworld - XML

The document describes code for several Android applications and activities: 1. A Hello World application with an activity_helloworld.xml layout and HelloWorldActivity class to display text. 2. A Welcome to Tech application with similar files to display different text. 3. An application to display a login form with activity_loginform.xml layout and LoginFormActivity class containing EditText fields and a submit button. 4. An application with activities for displaying images, a grid view, and progress bar to demonstrate various Android UI elements. The code includes XML layout files and Java activity classes to implement the interfaces.

Uploaded by

Jakka hitheshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Android Application To Display Hello World Activity - Helloworld - XML

The document describes code for several Android applications and activities: 1. A Hello World application with an activity_helloworld.xml layout and HelloWorldActivity class to display text. 2. A Welcome to Tech application with similar files to display different text. 3. An application to display a login form with activity_loginform.xml layout and LoginFormActivity class containing EditText fields and a submit button. 4. An application with activities for displaying images, a grid view, and progress bar to demonstrate various Android UI elements. The code includes XML layout files and Java activity classes to implement the interfaces.

Uploaded by

Jakka hitheshini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 46

16HU1A0526

ANDROID APPLICATION TO DISPLAY HELLO WORLD

activity_helloworld.xml:

<RelativeLayout
android:xmlns=”http://android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_horizontal=”true”
android:text=”HELLO WORLD”
android:id=”+@id/Helloworld / >
</Relative layout>

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

HelloWorldActivity.java :

package.com.androidunreleased.helloworld;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
public class HelloworldActivity extends Activity
{
@override
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_helloworld);
}
public void onClick(View v)
{
TextView t=(TextView)this.findViewById(R.id.D);
t.setText(“HELLO WORLD”);
}
}

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

ANDROID APPLICATION TO DISPLAY WELCOME TO TECH

activity_welcometotech.xml :

<Relative layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_horizontal=”true”
android:text=”WELCOME TO TECH”
android:id=”+@id/D”
/>
</Relative layout>

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

WelcometotechActivity.java:
package.com.androidunreleased.Welcometotech;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
public class WelcometotechActivity extends Activity
{
@override
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Welcometotech);
}
public void onClick(View v)
{
TextView t=(TextView)this.findViewById(R.id.D);
t.setText(“WELCOME TO TECH”);
}
}

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

TO DISPLAY AN LOGIN FORM

Activity_login form.xml file:

<Relative layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=”ENTER NAME” />
<EditText

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android :id=”+@id/D”/>
<TextView
android:layout_width="wrap_content"
android:layout_height=”"wrap_content"
android:text=”PASSWORD” />
<EditText
android:layout_width="wrap_content"

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

android:layout_height="wrap_content"
android:id=”+@id/D1”/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=”OK”
android: id=”+@id/D2”/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id=”+@id/D3”/>
</Relative layout>

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

Login form Activity.java file:

package.com.androidunreleased.Loginform;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import android.widget.Button;
import android.widget.EditText;
public class login form Activity extends Activity
{
@override
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Loginform);
Button b=(Button)this.findViewById(R.id.D2):

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

b.setonClickListener(new Button onClickListener()


{
public void onClick(View v)
{
TextView t=(TextView)this.findViewById(R.id.D3);
EditText e1=(EditText)this.findViewById(R.id.D);
EditText e2=(EditText)this.findViewById(R.id.D1);
String s=”Entername”+e1.getText().tostring()
+”password”+e2.getText().tostring();
t.setText(s);
});
}
}

IMAGE VIEW

Activity_imageview.xml file
<Relative layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<Image View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id=”+@id/i”
android:src=”@drawable/sweety”/>
<Image View
android:layout_width="wrap_content"

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

android:layout_height="wrap_content"
android:id=”+@id/i1”
android:src=”@drawable/sanjana”/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=”CLICK ON THIS”
android:layout_gravity=”horizontal/vertical”
android:padding=”5dp”
android:textstyle=”bold”
android:textcolor=”black”/>
</Relative layout>

Image view.java file


package.com.androidunreleased.Imageview;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import android.widget.ImageView;
public class Image view extends Activity
{
@override
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Imageview);

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

ImageView i = (ImageView)this.findViewById(R.id.i1);
ImageView j = (ImageView)this.findViewById(R.id.i2);
i.setonClickListener(new image onClickListener()
}
public void onClick(View v)
{
i.set Visibility(V.VISIBLE);
v. Visibility(V.GONE);
});
}
j.setonClickListener(new image onClickListener()
public void onClick(View v)
{
j.set Visibility(v.VISIBLE);
v. Visibility(v.GONE);
});
}
}
TO DISPLAY ANGRID VEIW
Acvity_grid view.xml file:

<Linear layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=”SELECT FRUIT”

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

/>
<GridView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id=”+@id/A”
android:number of columns=”2”
android:horizontal spacing=”10dp”
android:vertical spacing=”10dp”
android: stretch mode=”column width”
/>
</LinearLayout>

Grid view.java file:


package.com.androidunreleased.Gidview;
import android.os.Bundle;
import android.app.Activity;
import android.view.onClickListener;
import android.view.ItemListerner;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.ArrayView;
import android.widget.GridView;
public class Gridview Activity extends Activity implements

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

ItemClickListener
{
@override
String[] s={“apple”, “banana”, “custer apple”, “grapes”, “gova”,
“mango”,
“orange”, “pine apple”};
TextView t;
GridView g;
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Gridview);
t=(TextView)this.findViewById(R.id.A);
g=(GridView)this.findViewById(R.id.B);
ArrayAdapter <string> a = new ArrayAdapter <String>
(this.android.R.layout.simplelist,s);
a.onItemClickListener(this);
}
public void onClick(AdapterView a, View v, int position, long id)
{
t.setText(“SELECT A FRUIT”);
}
}
}

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

TO DISPLAY THE PROGESS BAR

Actvity_progess bar.xml file

<Linear layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

android:text=”PROGESS BAR”
android:id=”+@id/A”
/>
<Toogle Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id=”+@id/B”
android:Text on=” ”
android:Text off=” ”
/>
</Linear layout>

Progess bar.java :

package.com.androidunreleased.Progessbar;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import android.widget.ToogleButton;
import android.widget.ProgessBar;
public class Progessbar Activity extends Activity
{
@override

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

MediaPlayer mp;
ProgessBar p;
ToogleButton tb;
TextView t;
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Progessbar);
t.set onClicklistener(this);
p.set pogess(0);
p.set Next(mp.get Duration());
}
public void onClick(View v)
{
if (tb isChecked)
{
t.setText(“select play button”);
mp = media player.create(R.raw.nayak);
mp.start();
update P;
}
else
{
t.setText(“select play button”);
t1.play();
update P();
}
}

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

PLAYING AUDIO FILE:

Activity_playing audio.xml file:

<Linear layout
android:xmlns="http://android.com/apk/src/layout"
andriod:tools="http:/schema.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

<Text view
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="play audio"
/>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="click me"
android:id="+@id/A"
/>
</Linear layout>

Playing audio.java file:

package.com.androidunreleased.Playaudio;
import android.os.Bundle;
import android.app.activity;
import android.view.onClickListener;
import android.widget.TextView;
import android.widget.Button;

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

public class Playaudio Activity extends Activity implements


onClicklistener
{
@override
{
super.onCreate(Bundle b)
set Content View(R.layout.activity_playaudio);
Button b=(Button)this.findViewById(R.id.A);
b.set onClicklistener(this);
}
public void onClick(view V)
{
Mediaplayer mp=mediaplayer.create(playAudioApp.R.syera);
mp.start();
}
}
}

TO DISPLAY AN LIST VIEW

Activity_list view.xml file

<Linear Layout
android:xmlns="http://android.com/apk/src/layout"
andriod:tools="http:/schema.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

android:orientation=”vertical”>
<List View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id=”+@id/A”
/>
<Text view
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="+@id/B"
/>
</Linear Layout>

List view.java file:

package.com.androidunreleased.Listview;
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import android.widget.ListView;
import android.widget.AdapterView;

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

import android.widget.ArrayAdapter;
import android.view.view;
import android.view.onItemListener;
public class list view Activity extends Activity
{
@override
TextView t;
ListView l;
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Listview);
Final string[] fruits={“apple”,
“mango” ,“orange” ,“grapes” ,“bananna”};
TextView t=(TextView)this.findViewById(R.id.B);
ListView l=(ListView)this.findViewById(R.id.A);
Final Array Adapter<string>array adpt=new Array
Adapter<string>(this,android.R.layout.simple_list_items,fruit
s);
Fruits list.setAdapter(array adpt);
Fruits list.setonItemClickListener(new.onItemClicklistener()

}
public void onItemClickListener(AdapterView a, View v, int
position, long id)
{
Selected opt.setText(“You have selected”+fruits[position]);
});

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

}
}

TO DISPLAY DATE AND TIME

Activity_Date and Time.xml file

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

<Relative layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<Button
android:id=”+@id/P”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=”Set date ”
/>
<Button
android:id=”+@id/A”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=”Set time”
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id=”+@id/K ”
/>
</Relative Layout>

Date and Time.java file:

package.com.androidunreleased.Date and time;

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
import android.widget.Button;
import java.util.Calender;
public class list view Activity extends Activity
{
@override
TextView t;
int dd,mm,yy,h,m.s;
calender c;
public void onCreate(Bundle b)
{
super.onCreate(b);
setContentView(R.layout.Activity_Date and time);
Button b= (Button)this.findViewById(R.id.P);
Button b1= (Button)this.findViewById(R.id.A);
t= (TextView)this.findViewById(R.id.K);
c=calender.getInstance();
dd=c.get(calender.Day);
mm=c.get(calender.Month);
yy=c.get(calender.Year);
h=c.get(calender.Hours);
m=c.get(calender.Minutes);
s=c.get(calender.Seconds);
t.setText(“current date=”+ dd +”:” + mm +”:” + yy );
t1.setText(“current time=”+ h +”:” + m +”:” + s);
{

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

b.set onClicklistener(new onClickListener()


Public void onClick(View v){
new DatePicker Dialog(DatePicker
Dialog.this.d,dd,mm,yy).show();
});
Private DatePicker Dialog.onDateSetListener d=new
DatePickerDialog.onDateSetListener()
{
Public void onDateSet(DatePicker View, int year, int monthOfYear
, int dateOfMonth)
{
yy=year;
mm=monthOfYear;
dd=dateOfMonth;
dispDate.setText(“current date is =”+ dd +”:” + mm +”:” + yy );
}
b1.set onClicklistener(new onClickListener()
Public void onClick(View v)
{
new TimePicker Dialog(TimePicker Dialog.this.d1,h,m,s).show();
});
}
Private timePicker Dialog.onTimeSetListener d=new
TimePicker Dialog.onTimeSetListener()
{
Public void onTimeSet(TimePicker View, int hour, int
minutesOfHour ,
int secondsOfminuntes)

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

{
h=hours;
minutes= minutesOfHour;
s= secondsOfminuntes;
disptime.setText(“current date is =”+ h +”:” + m +”:” + s );
}
}
}
}

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

TO DISPLAY BUTTONS

Activity_buttons.xml:

<Relative layout
android:xmlns=”http:/android.com/apk/src/layout”
android:tools=”http:/schemas.android.com/tools”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop=”15dp”
android:layout_marginLeft=”20dp”
android:text=”apple”
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop=”15dp”
android:layout_marginRight=”20dp”
android:layout_alignTop=”true”
android:text=”mango”
/>

<Button
android:layout_width="wrap_content"

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

android:layout_height="wrap_content"
android:layout_marginTop=”15dp”
android:layout_alignparentLeft=”20dp”
android:layout_below=”+@id/apple”
android:text=”banana”
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignparentRight=”true”
android:layout_below=”+@ id/banana”
android:text=”kiwi”
/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_PaddingTop=”15dp”
android:layout_PaddingLeft=”15dp”
android:layout_PaddingLeft=”20dp”
android:text=”grapes”
/>

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB


16HU1A0526

2019-20/TECH/IV CSE/MAD LAB

You might also like