You are on page 1of 38

Develop a program to display Hello World on screen.

XML Files
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--textview-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

JAVA File
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Develop a program to implement linear layout and absolute layout.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="top"
android:baselineAligned="true"
android:divider="@color/black">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Login"
android:textSize="30sp"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="250dp"
android:layout_marginLeft="20dp"
android:textSize="30sp"/>
</LinearLayout>
Develop a program to implement frame layout, table layout and relative layout.
Table Layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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"
android:collapseColumns="1"
android:shrinkColumns="3"
android:backgroundTint="@color/black"
android:visibility="visible"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/purple_700"

android:textAlignment="center"
android:text="Student Record Table"
android:textSize="30sp"
android:textColor="@color/white"
android:textStyle="italic"/>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Roll No"
android:background="#FFEB3B"
android:textStyle="bold"
android:textAlignment="center"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textStyle="bold"
android:text="Name"
android:textAlignment="center"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Year"
android:background="#FFEB3B"
android:textStyle="bold"
android:textSize="20sp"
android:textAlignment="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Marks"
android:textStyle="bold"
android:textSize="20sp"
android:textAlignment="center"
/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFEB3B"
android:text="7"
android:textAlignment="center"
android:textSize="20sp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Anjali"
android:textAlignment="center"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TY"
android:background="#FFEB3B"
android:textSize="20sp"
android:textAlignment="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="92%"
android:textSize="20sp"
android:textAlignment="center"
/>
</TableRow>
</TableLayout>
FrameLayout
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/google"/>
</FrameLayout>
Develop a program to implement Text View and Edit Text.

XML Files

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="top"
android:baselineAligned="true"
android:divider="@color/black">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="30dp"
android:text="Login"
android:textAlignment="center"
android:textColor="#F80606"
android:textSize="50sp"
android:textStyle="italic" />
<EditText
android:layout_height="wrap_content"
android:layout_width="280dp"
android:layout_marginLeft="70dp"
android:textStyle="bold"
android:textSize="30sp"/>
</LinearLayout>
Develop a program to implement Auto Complete Text View.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:textSize="30dp"
android:padding="20dp"
/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/a"
android:completionThreshold="1"
android:ems="30">
</AutoCompleteTextView>
</LinearLayout>

JAVA Files
package com.example.autotextview;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AutoCompleteTextView;
import android.widget.ArrayAdapter;
public class MainActivity extends AppCompatActivity
{
String[] arr = {"Anjali", "Shivam", "India", "America"};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView auto = findViewById(R.id.a);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, arr);
auto.setThreshold(1);
auto.setAdapter(adapter);
}
}
Develop a program to implement Button, Image Button and Toggle Button.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<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">
<ToggleButton
android:id="@+id/togu"
android:layout_width="180dp"
android:layout_height="64dp"
android:layout_marginTop="200dp"
android:layout_marginLeft="90dp"
android:text="Power OFF"
android:textOff="Off"
android:textOn="On"
android:drawableStart="@drawable/selector"/>
<ImageButton
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="50dp"
android:src="@drawable/img"></ImageButton>
<ImageView
android:id="@+id/img"
android:layout_width="191dp"
android:layout_height="96dp"
android:layout_marginLeft="90dp"
android:layout_marginTop="300dp" />
<Button
android:id="@+id/battu"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="CLICK"
android:layout_marginLeft="150dp"
android:layout_marginTop="450dp"/>
</RelativeLayout>

JAVA Files

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ToggleButton toggle = findViewById(R.id.togu);
ImageView image = findViewById(R.id.img);
image.setImageDrawable(getResources().getDrawable(R.drawable.off));
toggle.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view){
if (toggle.isChecked()){
image.setImageDrawable(getResources().getDrawable(R.drawable.on));
} else{ image.setImageDrawable(getResources().getDrawable(R.drawable.off));
}
}
});
}
}
Develop a program to implement login window using above UI controls.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:layout_marginTop="10dp"
android:text="--LOGIN--"
android:textSize="40dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserID"
android:layout_marginLeft="30dp"
android:layout_marginTop="90dp"
android:textSize="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:layout_marginLeft="30dp"
android:layout_marginTop="150dp"
android:textSize="30dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="70dp"
android:textSize="30dp"
android:id="@+id/e1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="200dp"
android:layout_marginTop="130dp"
android:textSize="30dp"
android:id="@+id/e2"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dp"
android:layout_marginTop="200dp"
android:text="SIGN-IN"
android:textSize="30dp"
android:id="@+id/b1"/>
</RelativeLayout>
Develop a program to implement Checkbox, Radio Button and Radio Group.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
android:padding="16sp"
android:orientation="horizontal"
android:scrollbarSize="25sp"
tools:context=".MainActivity">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Name :"
android:textSize="20dp" />

<EditText
android:layout_width="270dp"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="5dp"
android:textSize="20dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="60dp"
android:text="Subject :"
android:textSize="20dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="50dp"
android:text="English"
android:textSize="20dp" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="220dp"
android:layout_marginTop="50dp"
android:checked="true"
android:text="Marathi"
android:textSize="20dp" />

<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="90dp"
android:text="Hindi"
android:textSize="20dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="140dp"
android:text="Gender:"
android:textSize="20dp" />

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="135dp"
android:text="Male"
android:textSize="20dp" />

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Female"
android:textSize="20dp" />

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Other"
android:textSize="20dp" />
</RadioGroup>

</RelativeLayout>
</ScrollView>
Develop a program to implement Progress Bar.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CLICK"
android:textSize="20sp"
android:layout_marginTop="20sp"
android:layout_marginLeft="150sp"
android:id="@+id/battu"/>
<ProgressBar
android:id="@+id/poggu"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="120sp"
android:layout_marginLeft="100sp"
android:accessibilityTraversalAfter="@+id/poggu"
android:indeterminateTint="#FFEB3B"
/>
</RelativeLayout>

JAVA Files
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1= findViewById(R.id.battu);
ProgressBar p1=findViewById(R.id.poggu);
p1.setVisibility(View.GONE);
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
p1.setVisibility(View.VISIBLE);
Toast.makeText(MainActivity.this,"loaded Successfully",
Toast.LENGTH_SHORT).show();

}
});
}
}
Develop a program to implement List View, Grid View, Image View and Scroll View.

ListView
XML Files
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ListView
android:id="@+id/l1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>

JAVA Files
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list= findViewById(R.id.l1);
List<String> d =new ArrayList<>();
d.add("Anjali");
d.add("Aarya");
d.add("Manju");
d.add("Sidhi");
d.add("Sonakshi");
d.add("Anushka");
d.add("Rashmika");
d.add("Sonakshi");
d.add("Anushka");
d.add("Rashmika");
d.add("Sonakshi");
d.add("Anushka");
d.add("Rashmika");
list.setAdapter(new
ArrayAdapter<String>(this,androidx.appcompat.R.layout.support_simple_spinner_dropdown_it
em,d));
}
}

GridView
XML Files
<?xml version="1.0" encoding="utf-8"?>
<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">
<GridView
android:id="@+id/g"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3">
</GridView>
</RelativeLayout>

JAVA Files
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView g= findViewById(R.id.g);
List<String> d = new ArrayList<>();
d.add("Roll_No.");
d.add("Student_Name");
d.add("Marks");
d.add("1");
d.add("Aarya");
d.add("80");
d.add("2");
d.add("Anjali");
d.add("90");
d.add("3");
g.setAdapter(new
ArrayAdapter<String>(this,androidx.appcompat.R.layout.support_simple_spinner_dropdown_it
em,d));
}
}
Develop a program to implement Custom Toast Alert.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:layout_marginTop="200dp"
android:layout_marginLeft="140dp"/>
</LinearLayout>

JAVA Files

public class MainActivity extends AppCompatActivity


{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button)findViewById(R.id.btnShow);
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Toast.makeText(MainActivity.this, "You Clicked on Button..",
Toast.LENGTH_SHORT).show();
}
});
}
}
Develop a program to implement Date and Time Picker.
XML Files
<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">
<DatePicker
android:layout_height="250dp"
android:layout_width="400dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"/>
<TimePicker
android:layout_width="400dp"
android:layout_height="300dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="300dp" />
</RelativeLayout>
Develop a program to implement new activity using explicit intent and implicit intent.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/google"
tools:context=".MainActivity">
<EditText
android:id="@+id/edu"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="60dp"
android:textSize="20dp"
android:textColor="@color/white"
android:backgroundTint="@color/white"
/>
<Button
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="CLICK"
android:textColor="@color/black"
android:backgroundTint="@color/white"
android:textSize="30dp"
android:layout_marginTop="150dp"
android:layout_marginLeft="120dp"
android:id="@+id/Battu"/>
</RelativeLayout>

JAVA Files
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1 = findViewById(R.id.Battu);
EditText e1 = findViewById(R.id.edu);
b1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
String url = e1.getText().toString();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
expli.setOnClickListener(view -> {
startActivity(new Intent(this,MainActivity2.class));
});

}
}
Develop a program to build Camera.
XML Files
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:textSize="20dp"
android:id="@+id/b3"/>
</LinearLayout>

JAVA files
public class MainActivity extends AppCompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button cam= findViewById(R.id.b3);
cam.setOnClickListener(view ->
{
startActivity(new Intent(MediaStore.ACTION_IMAGE_CAPTURE));
});
}
}
Create sample application with login module. (Check username and password) On successful
login, Change TextView “Login Successful”. And on login fail, alert user using Toast “Login fail”.
JAVA Files
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText edit = findViewById(R.id.e1);
EditText edit1 = findViewById(R.id.e2);
Button but = findViewById(R.id.b1);
but.setOnClickListener(view -> login(edit.getText().toString(),edit1.getText().toString()));
}
private void login(String id, String password)
{
if(id.equals("Anjali")&& password.equals("123"))
Toast.makeText(this,"login Successful", Toast.LENGTH_LONG).show();
else
Toast.makeText(this,"login Unsuccessful", Toast.LENGTH_SHORT).show();
}
}
Create login application where you will have to validate username and password till the
username and password is not validated, login button should remain disabled.

JAVA File

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText edit = findViewById(R.id.e1);
EditText edit1 = findViewById(R.id.e2);
Button but = findViewById(R.id.b1);
but.setOnClickListener(view -> login(edit.getText().toString(),edit1.getText().toString()));
}
private void login(String id, String password)
{
if(id.equals("Anjali")&& password.equals("123"))
Toast.makeText(this,"login Successful", Toast.LENGTH_LONG).show();
else
Toast.makeText(this,"login Unsuccessful", Toast.LENGTH_SHORT).show();
Button but = findViewById(R.id.b1);
but.setClickable(false);
}
}

You might also like