0% found this document useful (0 votes)
26 views39 pages

MAD Chapter Programs

The document outlines several Android application development tasks, including creating a search engine interface with autocomplete, calculating factorials, displaying selected checkboxes, designing a login page, implementing a time picker, using radio buttons, performing basic arithmetic operations, and converting text to speech. Each task includes the necessary XML layout and Java code for the main activity. The document serves as a guide for practicing Android programming concepts and UI design.

Uploaded by

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

MAD Chapter Programs

The document outlines several Android application development tasks, including creating a search engine interface with autocomplete, calculating factorials, displaying selected checkboxes, designing a login page, implementing a time picker, using radio buttons, performing basic arithmetic operations, and converting text to speech. Each task includes the necessary XML layout and Java code for the main activity. The document serves as a guide for practicing Android programming concepts and UI design.

Uploaded by

hukesakshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MAD IMP Programs which are ask in previous year question paper od 3 rd and 4th chapter

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

protected void onCreate(Bundle savedInstanceState)

[Link](savedInstanceState);

setContentView([Link].activity_main);

AutoCompleteTextView autoCompleteTextView = findViewById([Link]);

String[] searchSuggestions = {"Google", "Bing", "Yahoo", "DuckDuckGo", "Baidu", "Yandex"

};

ArrayAdapter<String> adapter = new ArrayAdapter<>(

this, [Link].simple_dropdown_item_1line, searchSuggestions);

[Link](adapter);

[Link](1); // Start suggesting from 1 character

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];

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);
EditText numberInput = findViewById([Link]);

TextView resultView = findViewById([Link]);

Button calculateButton = findViewById([Link]);

[Link](v -> {

String input = [Link]().toString();

[Link](![Link]() ? "Factorial: " + factorial([Link](input)) :


"Enter a number");

});

private long factorial(int n) {

long result = 1;

for (int i = 2; i <= n; i++) result *= i;

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];

public class MainActivity extends AppCompatActivity {

CheckBox cb1, cb2, cb3, cb4, cb5;

Button showButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

[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

public void onClick(View v) {

StringBuilder selected = new StringBuilder("Selected: ");

if ([Link]()) [Link]([Link]()).append(", ");


if ([Link]()) [Link]([Link]()).append(", ");

if ([Link]()) [Link]([Link]()).append(", ");

if ([Link]()) [Link]([Link]()).append(", ");

if ([Link]()) [Link]([Link]()).append(", ");

if ([Link]().equals("Selected: ")) {

[Link]([Link], "No option selected",


Toast.LENGTH_SHORT).show();

} else {

// Remove last comma and space

[Link]([Link]() - 2);

[Link]([Link], [Link](), Toast.LENGTH_SHORT).show();

});

4. Write an xml file to create login page using Table Layout.


activity_main.xml

<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:text="Selected Time: "

android:textSize="18sp"

android:layout_marginTop="12dp"/>

</LinearLayout>

[Link]

Package [Link];
import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

private TextView timeView;

private TimePicker timePicker;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

timeView = findViewById([Link]);

timePicker = findViewById([Link]);

[Link]((view, hourOfDay, minute) -> {

String time = [Link]("%02d:%02d", hourOfDay, minute);

[Link]("Selected Time: " + time);

});

}}

6. Develop an android application using radio button.


activity_main.xml

<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];

public class MainActivity extends AppCompatActivity {

private RadioGroup radioGroup;


@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

radioGroup = findViewById([Link]);

[Link]((group, checkedId) -> {

RadioButton selected = findViewById(checkedId);

[Link]([Link], "Selected: " + [Link](),


Toast.LENGTH_SHORT).show();

});

7. Develop a program to perform addition, subtraction, division, multiplication of two


numbers and display the result. (Use appropriate UI controls)
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/num1"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter first number"

android:inputType="numberDecimal"/>

<EditText
android:id="@+id/num2"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter second number"

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];

public class MainActivity extends AppCompatActivity {

private EditText num1, num2;

private TextView result;

@Override

protected void onCreate(Bundle savedInstanceState) {


[Link](savedInstanceState);

setContentView([Link].activity_main);

num1 = findViewById([Link].num1);

num2 = findViewById([Link].num2);

result = findViewById([Link]);

findViewById([Link]).setOnClickListener(v -> calculate('+'));

findViewById([Link]).setOnClickListener(v -> calculate('-'));

findViewById([Link]).setOnClickListener(v -> calculate('*'));

findViewById([Link]).setOnClickListener(v -> calculate('/'));

private void calculate(char operator) {

String n1 = [Link]().toString();

String n2 = [Link]().toString();

if ([Link]() || [Link]()) {

[Link]("Please enter both numbers");

return;

double number1 = [Link](n1);

double number2 = [Link](n2);

double res = 0;

switch (operator) {

case '+': res = number1 + number2; break;

case '-': res = number1 - number2; break;

case '*': res = number1 * number2; break;

case '/':

if (number2 != 0) res = number1 / number2;

else {
[Link]("Cannot divide by zero");

return;

break;

[Link]("Result: " + res);

8. Develop an application to convert “thanks” text to speech as given in the following


GUI.
activity_main.xml

<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:text="Android Text to Speech (TTS) Demo"


android:textSize="18sp"

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:text="CLICK TO CONVERT TEXT TO SPEECH"

android:layout_marginTop="16dp"/>

</LinearLayout>

[Link]

Package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

private TextToSpeech tts;

private EditText inputText;


@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

inputText = findViewById([Link]);

Button convertButton = findViewById([Link]);

tts = new TextToSpeech(this, status -> {

if (status == [Link]) {

[Link]([Link]);

});

[Link](v -> {

String text = [Link]().toString().trim();

if (![Link]()) {

[Link](text, TextToSpeech.QUEUE_FLUSH, null, null);

});

@Override

protected void onDestroy() {

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"

android:text="TURN OFF BLUETOOTH"/>

</LinearLayout>

[Link]

Package [Link];

import [Link];

import [Link];

import [Link];
import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

private BluetoothAdapter bluetoothAdapter;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

bluetoothAdapter = [Link]();

Button onButton = findViewById([Link]);

Button offButton = findViewById([Link]);

[Link](v -> turnOnBluetooth());

[Link](v -> turnOffBluetooth());

private void turnOnBluetooth() {

if (bluetoothAdapter != null && ![Link]()) {

[Link]();

[Link](this, "Bluetooth Turned ON", Toast.LENGTH_SHORT).show();

} else {

[Link](this, "Bluetooth is already ON", Toast.LENGTH_SHORT).show();

private void turnOffBluetooth() {

if (bluetoothAdapter != null && [Link]()) {

[Link]();

[Link](this, "Bluetooth Turned OFF", Toast.LENGTH_SHORT).show();


} else {

[Link](this, "Bluetooth is already OFF", Toast.LENGTH_SHORT).show();

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:text="Result will appear here"

android:textSize="20sp"/>

</LinearLayout>

[Link]

Package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

TextView dateTimeView;

Button dateButton, timeButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

dateTimeView = findViewById([Link]);

dateButton = findViewById([Link]);

timeButton = findViewById([Link]);

[Link](v -> pickDate());

[Link](v -> pickTime());

}
private void pickDate() {

Calendar c = [Link]();

new DatePickerDialog(this, (view, y, m, d) ->

[Link]("Date: " + d + "/" + (m + 1) + "/" + y),

[Link]([Link]), [Link]([Link]),
[Link](Calendar.DAY_OF_MONTH)).show();

private void pickTime() {

Calendar c = [Link]();

new TimePickerDialog(this, (view, h, m) ->

[Link]("Time: " + h + ":" + [Link]("%02d", m)),

[Link](Calendar.HOUR_OF_DAY), [Link]([Link]), false).show();

11. Design a employee registration form using UI component.


activity_main.xml

<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];

public class MainActivity extends AppCompatActivity {

EditText nameInput, ageInput, departmentInput;

RadioGroup genderGroup;

Button submitButton;
@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

nameInput = findViewById([Link]);

ageInput = findViewById([Link]);

departmentInput = findViewById([Link]);

genderGroup = findViewById([Link]);

submitButton = findViewById([Link]);

[Link](v -> registerEmployee());

private void registerEmployee() {

String name = [Link]().toString().trim();

String age = [Link]().toString().trim();

String department = [Link]().toString().trim();

int selectedId = [Link]();

RadioButton selectedGender = findViewById(selectedId);

if ([Link]() || [Link]() || [Link]() || selectedId == -1) {

[Link](this, "Please fill all fields", Toast.LENGTH_SHORT).show();

} else {

String result = "Name: " + name + "\nAge: " + age + "\nDepartment: " + department +

"\nGender: " + [Link]().toString();

[Link](this, result, Toast.LENGTH_LONG).show();

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];

public class MainActivity extends AppCompatActivity {

ListView listView;

BluetoothAdapter bluetoothAdapter;

ArrayList<String> deviceList;

ArrayAdapter<String> arrayAdapter;
@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

listView = findViewById([Link]);

bluetoothAdapter = [Link]();

if (bluetoothAdapter == null) {

[Link](this, "Bluetooth not supported", Toast.LENGTH_SHORT).show();

return;

if (![Link]()) {

[Link](this, "Please turn on Bluetooth", Toast.LENGTH_SHORT).show();

} else {

showPairedDevices();

private void showPairedDevices() {

Set<BluetoothDevice> pairedDevices = [Link]();

deviceList = new ArrayList<>();

if ([Link]() > 0) {

for (BluetoothDevice device : pairedDevices) {

[Link]([Link]() + " - " + [Link]());

} else {

[Link]("No Paired Devices Found");

arrayAdapter = new ArrayAdapter<>(this, [Link].simple_list_item_1, deviceList);

[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];

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

[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:text="Result will appear here"

android:textSize="20sp"/>

</LinearLayout>

[Link]
Package [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

EditText inputTemp;

TextView resultView;

ToggleButton toggleButton;

Button convertButton;

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

inputTemp = findViewById([Link]);

resultView = findViewById([Link]);

toggleButton = findViewById([Link]);

convertButton = findViewById([Link]);

[Link](v -> convertTemperature());

private void convertTemperature() {

String input = [Link]().toString().trim();

if ([Link]()) {

[Link]("Please enter a value");

return;

}
double temp = [Link](input);

double result;

if ([Link]()) { // Celsius to Fahrenheit

result = (temp * 9/5) + 32;

[Link]("Fahrenheit: " + result);

} else { // Fahrenheit to Celsius

result = (temp - 32) * 5/9;

[Link]("Celsius: " + 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:text="Numbers will appear here"

android:textSize="20sp"

android:layout_marginBottom="10dp"/>

<TableRow>
<Button android:id="@+id/button1" android:text="1" android:layout_weight="1"/>

<Button android:id="@+id/button2" android:text="2" android:layout_weight="1"/>

<Button android:id="@+id/button3" android:text="3" android:layout_weight="1"/>

</TableRow>

<TableRow>

<Button android:id="@+id/button4" android:text="4" android:layout_weight="1"/>

<Button android:id="@+id/button5" android:text="5" android:layout_weight="1"/>

<Button android:id="@+id/button6" android:text="6" android:layout_weight="1"/>

</TableRow>

<TableRow>

<Button android:id="@+id/button7" android:text="7" android:layout_weight="1"/>

<Button android:id="@+id/button8" android:text="8" android:layout_weight="1"/>

<Button android:id="@+id/button9" android:text="9" android:layout_weight="1"/>

</TableRow>

<TableRow>

<Button android:id="@+id/button0" android:text="0" android:layout_weight="1"/>

<Button android:id="@+id/submitButton" android:text="Submit"


android:layout_weight="1"/>

<Button android:id="@+id/clearButton" android:text="Clear" android:layout_weight="1"/>

</TableRow>

</TableLayout>

[Link]

Package [Link];

import [Link];

import [Link];

import [Link];

import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

TextView resultView;

StringBuilder inputNumbers = new StringBuilder();

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main)

resultView = findViewById([Link]);

for (int i = 0; i <= 9; i++) {

int resID = getResources().getIdentifier("button" + i, "id", getPackageName());

findViewById(resID).setOnClickListener(this::onNumberClick);

findViewById([Link]).setOnClickListener(v -> {

[Link]("Numbers: " + [Link]());

});

findViewById([Link]).setOnClickListener(v -> {

[Link](0);

[Link]("Cleared");

});

public void onNumberClick(View view) {

Button button = (Button) view;

[Link]([Link]().toString());

[Link]("Clicked: " + [Link]());

}
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];

public class MainActivity extends AppCompatActivity {

private ProgressBar circularProgress;

private int progressStatus = 0;

private Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

circularProgress = findViewById([Link]);

new Thread(() -> {

while (progressStatus < 100) {

progressStatus += 1;

[Link](() -> [Link](progressStatus));

try {

[Link](100);

} catch (InterruptedException e) {

[Link]();

}).start();

17. Develop a program for Rectangular 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/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];

public class MainActivity extends AppCompatActivity {

private ProgressBar rectangularProgress;

private int progressStatus = 0;

private Handler handler = new Handler();

@Override

protected void onCreate(Bundle savedInstanceState) {

[Link](savedInstanceState);

setContentView([Link].activity_main);

rectangularProgress = findViewById([Link]);

new Thread(() -> {

while (progressStatus < 100) {

progressStatus += 1;

[Link](() -> [Link](progressStatus));

try {
[Link](100);

} catch (InterruptedException e) {

[Link]();

}).start();

You might also like