PracticalList of Mad
PracticalList of Mad
PracticalList of Mad
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
android:textSize="24sp"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:layout_marginTop="8dp"/>
<TextView
android:id="@+id/marksTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Marks: "
android:textSize="24sp"
android:layout_below="@id/nameTextView"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/marksEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Marks"
android:layout_marginTop="8dp"/>
</LinearLayout>
package com.example.android;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
2.Write a program to place name, age and mobile number linearly (vertical) on the display screen
using Linear layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
android:textSize="24sp"
android:layout_marginTop="50dp"/>
<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Name"
android:layout_marginTop="10dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"/>
<TextView
android:id="@+id/marksTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age: "
android:textSize="24sp"
android:layout_marginTop="20dp"/>
<EditText
android:id="@+id/marksEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:layout_marginTop="10dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile: "
android:textSize="24sp"
android:layout_marginTop="20dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Mob.no"
android:layout_marginTop="10dp"
android:layout_marginStart="50dp"
android:layout_marginEnd="50dp"/>
</LinearLayout>
package com.example.android;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
3. Write a program to display 10 students basic information in a table form using Table layout.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TableLayout
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*">
</TableLayout>
</ScrollView>
package com.example.android;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
{super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Student information
String[][] students = {
headersRow.addView(nameHeader);
headersRow.addView(ageHeader);
headersRow.addView(mobileHeader);
tableLayout.addView(headersRow);
}
4. Write a program to accept username and password from the end user using Text View and Edit
Text.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"/>
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter username"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Enter password"/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"/>
</LinearLayout>
package com.example.android;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
loginButton = findViewById(R.id.loginButton);
loginButton.setOnClickListener(new View.OnClickListener()
{@Override
} else {
});
}
5.Write a program to create a first display screen of any search engine using Auto Complete Text
View.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Search" android:completionThreshold="1"
/>
</RelativeLayout>
package com.example.android;
import android.os.Bundle;
import android.widget.ArrayAdapter;
androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
};
@Override
{super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
autoCompleteTextView.setAdapter(adapter);
}
6. Write a program to create a toggle button to display On/Off Bluetooth on the display screen.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity">
<ToggleButton android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff=" Bluetooth OFF"
android:textOn=" Bluetooth ON"
android:layout_centerInParent="true" />
<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OFF" android:textSize="24sp"
android:layout_below="@id/toggleButton"
android:layout_centerHorizontal="true"
android:paddingTop="16dp" />
</RelativeLayout>
package com.example.android;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;
@Override
{super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
toggleButton = findViewById(R.id.toggleButton);
toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{@Override
{if (isChecked)
{ textView.setText("ON");
} else {
textView.setText("OFF");
});
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN"
android:textStyle="bold"
android:layout_gravity="center"
android:textSize="50dp"
android:textColor="@color/black"/>
<TextView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your name:"
android:textSize="20dp"
android:textColor="@color/black"/>
<EditText
android:textAlignment="center"
android:layout_marginTop="30dp"
android:background="@drawable/border"
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Your name" />
<TextView
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter password:"
android:textSize="20dp"
android:textColor="@color/black"/>
<EditText
android:textAlignment="center"
android:layout_marginTop="30dp"
android:background="@drawable/border"
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Your password" />
<Button
android:layout_marginTop="30dp"
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Login" />
<TextView
android:layout_marginTop="30dp"
android:id="@+id/messageTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
package com.example.helloworld;
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;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText usernameEditText;
private EditText passwordEditText;
private Button loginButton;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
loginButton = findViewById(R.id.loginButton);
messageTextView = findViewById(R.id.messageTextView);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
String username = usernameEditText.getText().toString();
String password = passwordEditText.getText().toString();
REGISTER PAGE:-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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:textAlignment="center"
android:text="Student Registration"
android:textStyle="bold"
android:layout_gravity="center"
android:textSize="50dp"
android:textColor="@color/black"/>
<EditText
android:paddingStart="18dp"
android:layout_marginTop="40dp"
android:id="@+id/nameEditText"
android:background="@drawable/border"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Name" />
<EditText
android:paddingStart="18dp"
android:layout_marginTop="40dp"
android:id="@+id/classEditText"
android:background="@drawable/border"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Class" />
<EditText
android:paddingStart="18dp"
android:layout_marginTop="40dp"
android:id="@+id/emailEditText"
android:background="@drawable/border"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Email" />
<EditText
android:paddingStart="18dp"
android:layout_marginTop="40dp"
android:id="@+id/mobileEditText"
android:background="@drawable/border"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Mobile Number"
android:inputType="phone" />
<EditText
android:paddingStart="18dp"
android:layout_marginTop="40dp"
android:id="@+id/addressEditText"
android:background="@drawable/border"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="Address" />
<Button
android:layout_marginTop="40dp"
android:id="@+id/registerButton"
android:background="@drawable/border"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Register" />
</LinearLayout>
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
nameEditText = findViewById(R.id.nameEditText);
classEditText = findViewById(R.id.classEditText);
emailEditText = findViewById(R.id.emailEditText);
mobileEditText = findViewById(R.id.mobileEditText);
addressEditText = findViewById(R.id.addressEditText);
registerButton = findViewById(R.id.registerButton);
// Perform registration logic here, such as sending data to a server or storing locally
}
});
}
}
8. Write a program to show five checkboxes and toast selected checkbox’s.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:background="@drawable/border"
android:layout_marginTop="30dp"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="FRUITS"
android:textStyle="bold"
android:layout_gravity="center"
android:textSize="50dp"
android:textColor="@color/black"/>
<CheckBox
android:layout_marginTop="30dp"
android:id="@+id/checkbox1"
android:layout_marginLeft="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:scaleX="2"
android:scaleY="2"
android:text="Mango" />
<CheckBox
android:layout_marginTop="30dp"
android:id="@+id/checkbox2"
android:layout_marginLeft="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:scaleX="2"
android:scaleY="2"
android:text="Orange" />
<CheckBox
android:layout_marginTop="30dp"
android:id="@+id/checkbox3"
android:layout_marginLeft="95dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:scaleX="2"
android:scaleY="2"
android:text="WaterMelon" />
<CheckBox
android:layout_marginTop="30dp"
android:id="@+id/checkbox4"
android:layout_marginLeft="75dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:scaleX="2"
android:scaleY="2"
android:text="Grapes" />
<CheckBox
android:id="@+id/checkbox5"
android:layout_marginTop="30dp"
android:layout_marginLeft="70dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:scaleX="2"
android:scaleY="2"
android:text="Apple" />
<Button
android:layout_marginTop="30dp"
android:id="@+id/showSelectedButton"
android:layout_width="match_parent"
android:layout_height="70dp"
android:text="Selected Fruits" />
</LinearLayout>
package com.example.helloworld;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{
private CheckBox checkbox1, checkbox2, checkbox3, checkbox4, checkbox5;
private Button showSelectedButton;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkbox1 = findViewById(R.id.checkbox1);
checkbox2 = findViewById(R.id.checkbox2);
checkbox3 = findViewById(R.id.checkbox3);
checkbox4 = findViewById(R.id.checkbox4);
checkbox5 = findViewById(R.id.checkbox5);
showSelectedButton = findViewById(R.id.showSelectedButton);
showSelectedButton.setOnClickListener(new View.OnClickListener()
{
@Override
12.Write a program to display image using Image View and the button named as “changed Image”.
Once you click on button another image should get displayed.
13.Write a program to display 3 checkboxes and one button named “ordered “.once you click on
button it should toast different selected checkboxes along with items individual and total price.
14.Write a program to display Time Picker and Date picker with different mode.
15.Write a program to create Hello World Activity using all lifecycles methods to display messages
sing Log.d.
16.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.
18.Write a program to display the list of sensors supported by the mobile device.
19.Write a program to capture image and display in image view.
20.Write a program to turn on, turn off, Paired Devices List Bluetooth.
22.Write a program to create login form and display login successful /unsuccessful toast message.