Professional Documents
Culture Documents
MAD Programs
MAD Programs
MAD Programs
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Registration "
android:textStyle="bold"
android:textSize="40dp" />
<EditText
android:layout_width="324dp"
android:layout_height="66dp"
android:text="Username" />
<EditText
android:layout_width="318dp"
android:layout_height="63dp"
android:text="Password" />
<EditText
android:layout_width="324dp"
android:layout_height="66dp"
android:text="Phone No" />
<EditText
android:layout_width="324dp"
android:layout_height="66dp"
android:text="Email Id" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="REGISTER"/>
</LinearLayout>
Output
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_x="60dp"
android:layout_y="78dp"
android:text="Registration "
android:textColor="@color/black"
android:textSize="40dp"
android:textStyle="bold" />
<EditText
android:layout_width="324dp"
android:layout_height="66dp"
android:layout_x="16dp"
android:layout_y="174dp"
android:text="Username" />
<EditText
android:layout_width="318dp"
android:layout_height="63dp"
android:layout_x="20dp"
android:layout_y="254dp"
android:text="Password" />
<EditText
android:layout_width="324dp"
android:layout_height="66dp"
android:layout_x="22dp"
android:layout_y="339dp"
android:text="Phone No" />
<EditText
android:layout_width="324dp"
android:layout_height="66dp"
android:layout_x="26dp"
android:layout_y="421dp"
android:text="Email Id" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="40dp"
android:layout_y="528dp"
android:text="REGISTER"
android:textColor="@color/black" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="220dp"
android:layout_y="521dp"
android:text="Login"
android:textColor="@color/black" />
</AbsoluteLayout>
Output:
Design Registration Activity by using Relative Layout.
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration"
android:textColor="#151514"
android:textSize="40dp"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:layout_below="@+id/text1"/>
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:layout_below="@+id/name"/>
<EditText
android:id="@+id/gmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gmail"
android:layout_below="@+id/phone"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_below="@+id/gmail"/>
<Button
android:id="@+id/reg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="Register"
android:layout_marginTop="67dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="50dp"
android:layout_below="@+id/password"/>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="Login"
android:layout_below="@+id/password"
android:layout_marginTop="65dp"
android:layout_marginStart="90dp"
android:layout_marginLeft="90dp"
android:layout_toEndOf="@+id/reg"
android:layout_toRightOf="@+id/reg"/>
</RelativeLayout>
Output:
Design Registration Activity by using Table Layout.
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration"
android:textColor="#151514"
android:textSize="40dp"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:layout_below="@+id/text1"/>
<EditText
android:id="@+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:layout_below="@+id/name"/>
<EditText
android:id="@+id/gmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Gmail"
android:layout_below="@+id/phone"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_below="@+id/gmail"/>
<Button
android:id="@+id/reg"
android:layout_width="385dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_below="@+id/password"
android:layout_marginStart="5dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="67dp"
android:text="Register"
android:textColor="@color/black"/>
</TableLayout>
Output:
Design Login Activity and display entered username and password using Toast.
Design and develop the program to perform addition of two numbers.
XML
<?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"
android:background="#858058"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="81dp">
<TextView
android:id="@+id/textView_second_no"
android:layout_width="150dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="150dp"
android:text="Second number"
android:textSize="20dp" />
<EditText
android:id="@+id/editText_second_no"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_marginLeft="200dp"
android:layout_marginTop="150dp"
android:inputType="number"
tools:ignore="MissingConstraints" />
<!-- button for run add logic and view result -->
<Button
android:id="@+id/add_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="110dp"
android:layout_marginTop="250dp"
android:text="ADD" />
</RelativeLayout>
Java file
package com.example.a19202b0021;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
EditText number1;
EditText number2;
Button Add_button;
TextView result;
int ans=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Output
Write a program to create a toggle button to display ON / OFF Bluetooth on the
display screen.
<TextView
android:id="@+id/text1"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Toggle"
android:textSize="30dp"
tools:ignore="MissingConstraints" />
<ToggleButton
android:id="@+id/t1"
android:layout_width="157dp"
android:layout_height="58dp"
android:layout_below="@+id/text1"
android:layout_centerHorizontal="true"
android:background="@color/purple_700"
tools:ignore="MissingConstraints"
android:gravity="center"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<EditText
android:id="@+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_below="@+id/edt1"
android:layout_marginTop="94dp"
android:text="1" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button1"
android:layout_toLeftOf="@+id/button3"
android:layout_toStartOf="@+id/button3"
android:text="2" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/button2"
android:layout_centerHorizontal="true"
android:text="3" />
<Button
android:id="@+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_toLeftOf="@+id/button2"
android:text="4" />
<Button
android:id="@+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button4"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2"
android:text="5" />
<Button
android:id="@+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_alignStart="@+id/button3"
android:layout_below="@+id/button3"
android:text="6" />
<Button
android:id="@+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button4"
android:layout_toLeftOf="@+id/button2"
android:text="7" />
<Button
android:id="@+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button5"
android:layout_alignStart="@+id/button5"
android:layout_below="@+id/button5"
android:text="8" />
<Button
android:id="@+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button6"
android:layout_alignStart="@+id/button6"
android:layout_below="@+id/button6"
android:text="9" />
<Button
android:id="@+id/buttonadd"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/edt1"
android:layout_alignRight="@+id/edt1"
android:layout_alignTop="@+id/button3"
android:layout_marginLeft="46dp"
android:layout_marginStart="46dp"
android:layout_toRightOf="@+id/button3"
android:text="+" />
<Button
android:id="@+id/buttonsub"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/buttonadd"
android:layout_alignLeft="@+id/buttonadd"
android:layout_alignRight="@+id/buttonadd"
android:layout_alignStart="@+id/buttonadd"
android:layout_below="@+id/buttonadd"
android:text="-" />
<Button
android:id="@+id/buttonmul"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buttonsub"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignStart="@+id/buttonsub"
android:layout_below="@+id/buttonsub"
android:text="*" />
<Button
android:id="@+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button7"
android:layout_toLeftOf="@+id/button2"
android:text="." />
<Button
android:id="@+id/button0"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button8"
android:layout_alignStart="@+id/button8"
android:layout_below="@+id/button8"
android:text="0" />
<Button
android:id="@+id/buttonC"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button9"
android:layout_alignStart="@+id/button9"
android:layout_below="@+id/button9"
android:text="C" />
<Button
android:id="@+id/buttondiv"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/buttonmul"
android:layout_alignLeft="@+id/buttonmul"
android:layout_alignRight="@+id/buttonmul"
android:layout_alignStart="@+id/buttonmul"
android:layout_below="@+id/buttonmul"
android:text="/" />
<Button
android:id="@+id/buttoneql"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/buttondiv"
android:layout_alignLeft="@+id/button10"
android:layout_alignRight="@+id/buttondiv"
android:layout_alignStart="@+id/button10"
android:layout_below="@+id/button0"
android:layout_marginTop="37dp"
android:text="=" />
</RelativeLayout>
Java File
package com.example.a19202b0021;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "1");
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "2");
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "3");
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "4");
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "5");
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "6");
}
});
button7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "7");
}
});
button8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "8");
}
});
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "9");
}
});
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ "0");
}
});
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (crunchifyEditText == null) {
crunchifyEditText.setText("");
} else {
mValueOne =
Float.parseFloat(crunchifyEditText.getText() + "");
crunchifyAddition = true;
crunchifyEditText.setText(null);
}
}
});
buttonSub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne =
Float.parseFloat(crunchifyEditText.getText() + "");
mSubtract = true;
crunchifyEditText.setText(null);
}
});
buttonMul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne =
Float.parseFloat(crunchifyEditText.getText() + "");
crunchifyMultiplication = true;
crunchifyEditText.setText(null);
}
});
buttonDivision.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
mValueOne =
Float.parseFloat(crunchifyEditText.getText() + "");
crunchifyDivision = true;
crunchifyEditText.setText(null);
}
});
buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueTwo =
Float.parseFloat(crunchifyEditText.getText() + "");
if (crunchifyAddition == true) {
crunchifyEditText.setText(mValueOne + mValueTwo +
"");
crunchifyAddition = false;
}
if (mSubtract == true) {
crunchifyEditText.setText(mValueOne - mValueTwo +
"");
mSubtract = false;
}
if (crunchifyMultiplication == true) {
crunchifyEditText.setText(mValueOne * mValueTwo +
"");
crunchifyMultiplication = false;
}
if (crunchifyDivision == true) {
crunchifyEditText.setText(mValueOne / mValueTwo +
"");
crunchifyDivision = false;
}
}
});
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText("");
}
});
button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crunchifyEditText.setText(crunchifyEditText.getText()
+ ".");
}
});
}
}
Output :
.
XML File
<?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"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">
<CheckBox
android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"
android:textSize="25dp"
android:layout_gravity="center"
android:padding="10dp"
android:checked="false"/>
<CheckBox
android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pythpn"
android:textSize="25dp"
android:layout_gravity="center"
android:padding="10dp"
android:checked="false"/>
<CheckBox
android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PHP"
android:textSize="25dp"
android:layout_gravity="center"
android:padding="10dp"
android:checked="false"/>
<CheckBox
android:id="@+id/cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:textSize="25dp"
android:layout_gravity="center"
android:padding="10dp"
android:checked="false"/>
<CheckBox
android:id="@+id/cb5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Java"
android:textSize="25dp"
android:layout_gravity="center"
android:padding="10dp"
android:checked="false"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="35dp"
android:layout_gravity="center"
android:padding="10dp"/>
</LinearLayout>
Java File
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
Button b;
StringBuffer sb;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = findViewById(R.id.btn);
cb1 = findViewById(R.id.cb1);
cb2 = findViewById(R.id.cb2);
cb3 = findViewById(R.id.cb3);
cb4 = findViewById(R.id.cb4);
cb5 = findViewById(R.id.cb5);
b.setOnClickListener(new View.OnClickListener() {
@Override
if (cb1.isChecked())
sb.append("Android");
if (cb2.isChecked())
sb.append("Python");
if (cb3.isChecked())
sb.append("PHP");
if (cb4.isChecked())
sb.append("Java");
if (cb5.isChecked())
sb.append("C");
Toast.makeText(getApplicationContext(), sb,
Toast.LENGTH_SHORT).show();
});
Output :
Write a program to use the radio Buttons.
XML File
<?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:text="Select your Subject ?"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:textSize="20dp"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/radia_id2"
android:text="C/C++ Programming"
android:textSize="20dp"/>
<RadioButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/radia_id3"
android:text="Data Structure"
android:textSize="20dp"/>
</RadioGroup>
<RadioButton
android:id="@+id/radia_id4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Algorithms"
android:textSize="20dp" />
</RelativeLayout>
Java File
package com.example.a19202b0021;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onClick(View v)
{
RadioButton radioButton
= (RadioButton)radioGroup
.findViewById(selectedId);
@Override
public void onClick(View v)
{
// Clear RadioGroup
// i.e. reset all the Radio Buttons
radioGroup.clearCheck();
}
});
}
}
Output:
Write a program to display different name of cities in List View and display toast
message when particular city is selected.
XML.File
<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">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
Mylist.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:textColor="#4d4d4d"
/>
String.xml
<resources>
<string name="app_name">ListView</string>
<string-array name="array_technology">
<item>Mumbai</item>
<item>Delhi</item>
<item>Bangalore </item>
<item>Hyderabad</item>
<item>Ahmedabad</item>
<item>Chennai</item>
<item>Kolkata</item>
<item>Surat</item>
<item>Pune</item>
<item>Jaipur</item>
<item>Lucknow</item>
<item>Kanpur</item>
</string-array>
</resources>
Java File
package com.example.a19202b0021;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View
view, int position, long l) {
// TODO Auto-generated method stub
String value=adapter.getItem(position);
Toast.makeText(getApplicationContext(),value,Toast.LENGTH_SHORT).show
();
}
});
}
}
Output :
Write a program to add buttons in Grid View.
XML File:
<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"
android:padding="40dp"
tools:context=".MainActivity">
<GridView
android:id="@+id/g"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#A383DD"
android:dividerHeight="1dp"
android:numColumns="2"/>
</RelativeLayout>
Mylist.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:id="@+id/textview"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="4dp"
android:textColor="#0000FF" />
Java file :
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
gridView=findViewById(R.id.g);
t1=findViewById(R.id.textview);
ArrayAdapter adapter=new
ArrayAdapter(this,R.layout.mylist,R.id.textview,city);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
String element="City Is: "+adapter.getItem(position);
Toast.makeText(getApplicationContext(),element,Toast.LENGTH_LONG).sho
w();
}
});
}
}
Output:
Write a program to create a HelloWorld Activity using all lifecycles methods to
display messages using Log.d.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@Override
protected void onStart() {
super.onStart();
Log.d("Life cycle","start method");
}
@Override
protected void onResume() {
super.onResume();
Log.d("Life cycle","Resume method");
}
@Override
protected void onPause(){
super.onPause();
Log.d("Life cycle","pause method");
}
@Override
protected void onStop(){
super.onStop();
Log.d("Life cycle","stop method");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.d("Life cycle","destroy method");
}
@Override
public void onRestart(){
super.onResort();
Log.d("Life cycle","Restart method");
}
}
Write a program to create a text field and a button “Navigate”. When you enter
“www.google.com” and press navigate button it should open google page.
activity_main.xml
<?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"
android:background="#9F8B71"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Explicit Intent Example"
android:id="@+id/b1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/b1"
android:text="Implicit Intent Example"
android:id="@+id/b2"/>
</RelativeLayout>
activity_second.xml
<?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=".MainActivity2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is Second Activity"
android:id="@+id/textView" />
</RelativeLayout>
Java file
package com.example.a19202b0021;
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;
import android.widget.TextView;
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent in = new Intent(getBaseContext(),
MainActivity2.class);
startActivity(in);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SecondActivity.java
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
Output :
Write a program to create button “Start Dialer”. When u click on this button it
should open the phone dialer.
XML File
<?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"
android:padding="40dp"
tools:context=".MainActivity">
<Button
android:id="@+id/b1"
android:text="Dialpad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Java file
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
b=findViewById(R.id.b1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_DIAL);
startActivity(i);
}
});
}
}
Output :
Write a program to create two screens. First screen will take one number input
from user. After click on Factorial button, second screen will open and it should
display factorial of the same number. Also specify which type of intent you will
use in this case.
MainActivity.xml
<?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"
android:padding="40dp"
android:background="@color/purple_200"
tools:context=".MainActivity">
<EditText
android:id="@+id/e1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textAlignment="center"/>
<Button
android:id="@+id/b1"
android:text="Factorial"
android:layout_below="@+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
MainActivity.java
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
MainAtivity2.xml
<?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"
android:padding="10dp"
android:id="@+id/f1"
tools:context=".MainActivity2">
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textAlignment="center"
android:textSize="100px"
android:textStyle="bold"/>
<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/t1"
android:layout_centerHorizontal="true"
android:text="BACK"/>
</RelativeLayout>
MainActivity.java
package com.example.a19202b0021;
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;
import android.widget.EditText;
import android.widget.TextView;
b=findViewById(R.id.b1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new
Intent(MainActivity2.this,MainActivity.class);
startActivity(i);
}
});
}
}
Output:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:text="Service"
android:textColor="@color/black"
android:textSize="35dp"
android:textStyle="bold" />
<Button
android:id="@+id/B1"
android:layout_width="190dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="190dp"
android:text="Start Service" />
<Button
android:id="@+id/B2"
android:layout_width="197dp"
android:layout_height="61dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="290dp"
android:text="Stop Service" />
</RelativeLayout>
Java file
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.B1);
b2=findViewById(R.id.B2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startService(new
Intent(getApplicationContext(),MyService.class));
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopService(new
Intent(getApplicationContext(),MyService.class));
}
});
}
}
Myservice
package com.example.a19202b0021;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.widget.Toast;
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet
implemented");
}
@Override
public int onStartCommand(Intent intent, int flags, int
startId) {
mp=MediaPlayer.create(this,R.raw.song);
mp.setLooping(true);
mp.start();
Toast.makeText(getApplicationContext(), "Service
Started", Toast.LENGTH_SHORT).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
mp.stop();
Toast.makeText(getApplicationContext(), "Service
Stopped", Toast.LENGTH_SHORT).show();
}
}
Output
Write a program to demonstrate all the system broadcast messages.
MainActivity.xml
<?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"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
</LinearLayout>
MainActivity.java
package com.example.a19202b0021;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
@Override
protected void onStart() {
super.onStart();
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
intentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
this.registerReceiver(myReceiver,intentFilter);
@Override
protected void onStop() {
super.onStop();
this.unregisterReceiver(myReceiver);
}
}
MyReceiver.java
package com.example.a19202b0021;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
@Override
public void onReceive(Context context, Intent intent) {
String actionstring=intent.getAction();
Toast.makeText(context,actionstring,Toast.LENGTH_LONG).show();
}
}
Output:
Write a program to capture an image and display it using image view.
<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"
android:padding="40dp"
android:background="#92DF95"
android:orientation="horizontal"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:id="@+id/text"
android:textSize="20dp"
android:gravity="center"/>
<ImageView
android:id="@+id/image"
android:layout_width="371dp"
android:layout_height="217dp"
android:layout_below="@+id/text"
android:layout_marginTop="81dp"
android:src="@drawable/image" />
<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="TAKE PHOTO" />
</RelativeLayout>
Java file
package com.example.a19202b0021;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
b1=findViewById(R.id.photo);
imageView=findViewById(R.id.image);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@Override
protected void onActivityResult(int requestCode, int resultCode,
@Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERA_REQUEST)
{
Bitmap image= (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}
Output:
Animation (res>anim>xml)
XML
<?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"
android:background="#9ECF75"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="340dp"
android:layout_height="416dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:src="@drawable/image" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:onClick="blink"
android:text="Blink" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_marginTop="20dp"
android:onClick="rotate"
android:text="Rotate" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_marginTop="75dp"
android:layout_marginRight="10dp"
android:onClick="fade"
android:text="Fade" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp"
android:layout_marginRight="10dp"
android:onClick="move"
android:text="Move" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_marginLeft="250dp"
android:layout_marginTop="20dp"
android:onClick="slide"
android:text="Slide" />
</RelativeLayout>
Java file
package com.example.anim;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
Move .xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="0%p"
android:toXDelta="75%p"
android:duration="800" />
</set>
Fade.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<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>
Blink.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<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>
Rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" >
</rotate>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="5000"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="5000" >
</rotate>
</set>
Output :
Ratate
Blink
Fade
Move
Paste the copied URL at the browser. It will open the following page.
Click on Create API key to generate API key.
After clicking on Create API key, it will generate our API key displaying the
following screen.
Copy this generated API key in our google_map_api.xml file
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.a19202b0021" >
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.19202B0021"
tools:targetApi="31" >
<!--
TODO: Before you run your application, you need a Google Maps API key.
https://developers.google.com/maps/documentation/android-sdk/get-api-key
Once you have your API key (it starts with "AIza"), define a new property in your
project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
"YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY" />
<activity
android:name=".MapsActivity"
android:exported="true"
android:label="@string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
Java
package com.example.a19202b0021;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng mumbai = new LatLng(19.085442, 72.875694);
mMap.addMarker(new MarkerOptions().position(mumbai).title("Marker in Mumbai"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mumbai, 10F));
}
}