MAD Chapter Programs
MAD Chapter Programs
1. Write a program to create first display screen of any search engine using auto
complete text view.
activity_main.xml
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search here"
android:textSize="18sp"
android:padding="12dp"
android:drawableStart="@android:drawable/ic_menu_search"
android:background="@android:color/white"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
};
[Link](adapter);
2. Develop android application to enter one number and display factorial of a number
once click on button.
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/numberInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter number"
android:inputType="number"/>
<Button
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"/>
<TextView
android:id="@+id/resultView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result here"
android:textSize="18sp"
android:layout_marginTop="12dp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
EditText numberInput = findViewById([Link]);
[Link](v -> {
});
long result = 1;
return result;
3. Write a program to show five checkboxes and toast selected checkboxes using linear
layout.
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<CheckBox
android:id="@+id/cb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1"/>
<CheckBox
android:id="@+id/cb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2"/>
<CheckBox
android:id="@+id/cb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3"/>
<CheckBox
android:id="@+id/cb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 4"/>
<CheckBox
android:id="@+id/cb5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 5"/>
<Button
android:id="@+id/showButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:layout_marginTop="12dp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
Button showButton;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
cb1 = findViewById([Link].cb1);
cb2 = findViewById([Link].cb2);
cb3 = findViewById([Link].cb3);
cb4 = findViewById([Link].cb4);
cb5 = findViewById([Link].cb5);
showButton = findViewById([Link]);
[Link](new [Link]() {
@Override
if ([Link]().equals("Selected: ")) {
} else {
[Link]([Link]() - 2);
});
<TableLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"
android:textSize="18sp"
android:padding="8dp"/>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:textSize="18sp"
android:padding="8dp"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Password"
android:inputType="textPassword"/>
</TableRow>
<TableRow>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="12dp"
android:padding="8dp"/>
</TableRow>
</TableLayout>
5. Develop an application to display analog Time Picker. Also display the selected time.
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"/>
<TextView
android:id="@+id/timeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginTop="12dp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
timeView = findViewById([Link]);
timePicker = findViewById([Link]);
});
}}
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1"/>
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2"/>
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3"/>
</RadioGroup>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link](savedInstanceState);
setContentView([Link].activity_main);
radioGroup = findViewById([Link]);
});
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/num1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>
<EditText
android:id="@+id/num2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add"/>
<Button
android:id="@+id/subButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtract"
android:layout_marginStart="8dp"/>
<Button
android:id="@+id/mulButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Multiply"
android:layout_marginStart="8dp"/>
<Button
android:id="@+id/divButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Divide"
android:layout_marginStart="8dp"/>
</LinearLayout>
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result: "
android:textSize="18sp"
android:layout_marginTop="16dp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
setContentView([Link].activity_main);
num1 = findViewById([Link].num1);
num2 = findViewById([Link].num2);
result = findViewById([Link]);
String n1 = [Link]().toString();
String n2 = [Link]().toString();
if ([Link]() || [Link]()) {
return;
double res = 0;
switch (operator) {
case '/':
else {
[Link]("Cannot divide by zero");
return;
break;
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextToSpeechDemo"
android:textSize="22sp"
android:textStyle="bold"
android:layout_marginBottom="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"/>
<EditText
android:id="@+id/inputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text"
android:text="thanks"/>
<Button
android:id="@+id/convertButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
[Link](savedInstanceState);
setContentView([Link].activity_main);
inputText = findViewById([Link]);
if (status == [Link]) {
[Link]([Link]);
});
[Link](v -> {
if (![Link]()) {
});
@Override
if (tts != null) {
[Link]();
[Link]();
[Link]();
}
9. Develop a program to TURN ON and OFF bluetooth.(Repeated)
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<Button
android:id="@+id/onButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TURN ON BLUETOOTH"
android:layout_marginBottom="16dp"/>
<Button
android:id="@+id/offButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
bluetoothAdapter = [Link]();
[Link]();
} else {
[Link]();
10. Develop an android application for Date and Time Picker.(Repeated Imp)
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<Button
android:id="@+id/dateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick Date"
android:layout_marginBottom="10dp"/>
<Button
android:id="@+id/timeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick Time"
android:layout_marginBottom="10dp"/>
<TextView
android:id="@+id/dateTimeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
TextView dateTimeView;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
dateTimeView = findViewById([Link]);
dateButton = findViewById([Link]);
timeButton = findViewById([Link]);
}
private void pickDate() {
Calendar c = [Link]();
[Link]([Link]), [Link]([Link]),
[Link](Calendar.DAY_OF_MONTH)).show();
Calendar c = [Link]();
<ScrollView xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/nameInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:layout_marginBottom="10dp"/>
<EditText
android:id="@+id/ageInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="Enter Age"
android:layout_marginBottom="10dp"/>
<EditText
android:id="@+id/departmentInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Department"
android:layout_marginBottom="10dp"/>
<RadioGroup
android:id="@+id/genderGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="10dp">
<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"/>
<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginStart="10dp"/>
</RadioGroup>
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"/>
</LinearLayout>
</ScrollView>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
RadioGroup genderGroup;
Button submitButton;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
nameInput = findViewById([Link]);
ageInput = findViewById([Link]);
departmentInput = findViewById([Link]);
genderGroup = findViewById([Link]);
submitButton = findViewById([Link]);
} else {
String result = "Name: " + name + "\nAge: " + age + "\nDepartment: " + department +
12. Design an android application to show the list of paired devices by Bluetooth.
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
ListView listView;
BluetoothAdapter bluetoothAdapter;
ArrayList<String> deviceList;
ArrayAdapter<String> arrayAdapter;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
listView = findViewById([Link]);
bluetoothAdapter = [Link]();
if (bluetoothAdapter == null) {
return;
if (![Link]()) {
} else {
showPairedDevices();
if ([Link]() > 0) {
} else {
[Link](arrayAdapter);
}
Permissions
<uses-permission android:name="[Link]"/>
<uses-permission android:name="[Link].BLUETOOTH_ADMIN"/>
13. Explain with example, code to create GUI using absolute layout (Assume suitable
data)
activity_main.xml
<AbsoluteLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_x="50dp"
android:layout_y="100dp"/>
<EditText
android:layout_width="150dp"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_x="50dp"
android:layout_y="180dp"
android:inputType="textPassword"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_x="70dp"
android:layout_y="250dp"/>
</AbsoluteLayout>
[Link]
Package [Link];
import [Link];
import [Link];
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
14. Write a program to convert temperature from celcius to farenhite and vice versa
using Toggle button. (Design UI as per your choice. Write XML and java file)
activity_main.xml
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="16dp">
<EditText
android:id="@+id/inputTemp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Temperature"
android:inputType="numberDecimal"
android:layout_marginBottom="10dp"/>
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="F to C"
android:textOn="C to F"
android:layout_marginBottom="10dp"/>
<Button
android:id="@+id/convertButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Convert"
android:layout_marginBottom="10dp"/>
<TextView
android:id="@+id/resultView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"/>
</LinearLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
EditText inputTemp;
TextView resultView;
ToggleButton toggleButton;
Button convertButton;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
inputTemp = findViewById([Link]);
resultView = findViewById([Link]);
toggleButton = findViewById([Link]);
convertButton = findViewById([Link]);
if ([Link]()) {
return;
}
double temp = [Link](input);
double result;
15. Design UI using table layout to display buttons with 0 – 9 numbers on it. Even
display submit and clear button. When user clicks on particular buttons and later
when clicks on submit button, it should display the numbers clicked.
activity_main.xml
<TableLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/resultView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_marginBottom="10dp"/>
<TableRow>
<Button android:id="@+id/button1" android:text="1" android:layout_weight="1"/>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
<TableRow>
</TableRow>
</TableLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
TextView resultView;
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main)
resultView = findViewById([Link]);
findViewById(resID).setOnClickListener(this::onNumberClick);
findViewById([Link]).setOnClickListener(v -> {
});
findViewById([Link]).setOnClickListener(v -> {
[Link](0);
[Link]("Cleared");
});
[Link]([Link]().toString());
}
16. Develop a program for Circular Progress bar
activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/circularProgress"
style="@android:style/[Link]"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="false"
android:max="100" />
</RelativeLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
circularProgress = findViewById([Link]);
progressStatus += 1;
try {
[Link](100);
} catch (InterruptedException e) {
[Link]();
}).start();
activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/rectangularProgress"
style="@android:style/[Link]"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="false"
android:max="100" />
</RelativeLayout>
[Link]
Package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Override
[Link](savedInstanceState);
setContentView([Link].activity_main);
rectangularProgress = findViewById([Link]);
progressStatus += 1;
try {
[Link](100);
} catch (InterruptedException e) {
[Link]();
}).start();