All Imp Mad Programs
All Imp Mad Programs
<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" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java code
package com.example.helloworldapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
2 Develop an android application to place Name, Age and Mobile
number on the display screen using Absolute Layout
Xml file
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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="10dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="40dp"
android:layout_y="20dp"
android:text="@string/name"
android:textSize="30sp" />
<TextView
android:id="@+id/tvAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="40dp"
android:layout_y="70dp"
android:text="@string/age"
android:textSize="30sp" />
<TextView
android:id="@+id/tvMobileNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="40dp"
android:layout_y="120dp"
android:text="@string/mobile_no"
android:textSize="30sp" />
</AbsoluteLayout>
Java file
package com.example.absolutelayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
strings.xml
<resources>
<string name="app_name">AbsoluteLayout</string>
<string name="name">Name : Suraj Pande</string>
<string name="age">Age : 26</string>
<string name="mobile_no">Mobile No. : 9851236547</string>
</resources>
Xml file
<?xml version="1.0" encoding="utf-8"?>
<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="10dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/tvName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/name"
android:textSize="40sp" />
<TextView
android:id="@+id/tvAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/age"
android:textSize="40sp" />
<TextView
android:id="@+id/tvMobileNo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/mobile_no"
android:textSize="40sp" />
</LinearLayout>
Java file
package com.example.linearlayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
strings.xml
<resources>
<string name="app_name">LinearLayout</string>
<string name="name">Name : Suraj Pande</string>
<string name="age">Age : 26</string>
<string name="mobile_no">Mobile No. : 9851236547</string>
</resources
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">
<TextView
android:id="@+id/studName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student name: Amol Chaudhari"
android:textSize="24sp" />
<TextView
android:id="@+id/studMarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Marks: 75.00"
android:textSize="24sp" />
</LinearLayout>
Java file
package com.example.studentdetailsapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Xml file
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/table_heading"
android:gravity="center_horizontal"
android:padding="10dp"
android:textColor="@android:color/black"
android:textStyle="bold"/>
<TableRow
android:id="@+id/headings"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#607D8B"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:layout_weight="1"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dept"
android:layout_weight="1"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City"
android:layout_weight="1"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Percentage"
android:layout_weight="1"
android:textColor="@android:color/white"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E7E7EB"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s1_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s1_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s1_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s1_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s2_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s2_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s2_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s2_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E7E7EB"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s3_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s3_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s3_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s3_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s4_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s4_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s4_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s4_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E7E7EB"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s5_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s5_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s5_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s5_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s6_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s6_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s6_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s6_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E7E7EB"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s7_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s7_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s7_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s7_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s8_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s8_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s8_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s8_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E7E7EB"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s9_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s9_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s9_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s9_percentage"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s10_name"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s10_dept"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s10_city"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/s10_percentage"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
Java file
package com.example.tablelayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
strings.xml
<resources>
<string name="app_name">TableLayout</string>
<string name="table_heading">Students Basic Information</string>
<string name="s1_name">Rohit</string>
<string name="s1_dept">COMP</string>
<string name="s1_city">Pune</string>
<string name="s1_percentage">85.21</string>
<string name="s2_name">Amit</string>
<string name="s2_dept">E & TC</string>
<string name="s2_city">Mumbai</string>
<string name="s2_percentage">75.26</string>
<string name="s3_name">Rohan</string>
<string name="s3_dept">COMP</string>
<string name="s3_city">Nashik</string>
<string name="s3_percentage">90.00</string>
<string name="s4_name">Santosh</string>
<string name="s4_dept">COMP</string>
<string name="s4_city">Dhule</string>
<string name="s4_percentage">79.24</string>
<string name="s5_name">Girish</string>
<string name="s5_dept">E & TC</string>
<string name="s5_city">Dhule</string>
<string name="s5_percentage">84.00</string>
<string name="s6_name">Aachal</string>
<string name="s6_dept">MECH</string>
<string name="s6_city">Shirpur</string>
<string name="s6_percentage">69.84</string>
<string name="s7_name">Riddhi</string>
<string name="s7_dept">COMP</string>
<string name="s7_city">Shirpur</string>
<string name="s7_percentage">73.57</string>
<string name="s8_name">Dinesh</string>
<string name="s8_dept">ELEC</string>
<string name="s8_city">Nandurbar</string>
<string name="s8_percentage">80.50</string>
<string name="s9_name">Kalpesh</string>
<string name="s9_dept">CIVIL</string>
<string name="s9_city">Jalgaon</string>
<string name="s9_percentage">71.30</string>
<string name="s10_name">Harish</string>
<string name="s10_dept">COMP</string>
<string name="s10_city">Dhule</string>
<string name="s10_percentage">72.47</string>
</resources>
Xml file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/string_data_types"
android:textStyle="bold"
style="@android:style/TextAppearance.Medium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="@string/string_int"
style="@android:style/TextAppearance.Large" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:text="@string/string_float"
style="@android:style/TextAppearance.Large" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="@string/string_char"
style="@android:style/TextAppearance.Large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="125dp"
android:text="@string/string_double"
style="@android:style/TextAppearance.Large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:text="@string/string_void"
style="@android:style/TextAppearance.Large"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="175dp"
android:text="@string/string_boolean"
style="@android:style/TextAppearance.Large"/>
</FrameLayout>
java file
package com.example.framelayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
strings.xml
<resources>
<string name="app_name">FrameLayout</string>
<string name="string_void">void</string>
<string name="string_boolean">boolean</string>
<string name="string_double">double</string>
<string name="string_char">char</string>
<string name="string_float">float</string>
<string name="string_int">int</string>
<string name="string_data_types">Data types in Object-Oriented
Programming</string>
</resources>
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:gravity="center_vertical"
android:orientation="vertical"
tools:context=".MainActivity"
android:padding="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Username"
style="@android:style/TextAppearance.Large"/>
<EditText
android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
style="@android:style/TextAppearance.Large" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Password"
android:layout_marginTop="10dp"
style="@android:style/TextAppearance.Large" />
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword"
style="@android:style/TextAppearance.Large" />
<Button android:id="@+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="right"
android:layout_marginTop="20dp"
style="@android:style/TextAppearance.Large"/>
</LinearLayout>
Java file
package com.example.userloginapp;
import android.support.v7.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_main);
etUsername = findViewById(R.id.etUsername);
etPassword = findViewById(R.id.etPassword);
btnLogin = findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Xml file
<?xml version="1.0" encoding="utf-8"?>
<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"
android:padding="10dp"
android:gravity="center">
<TextView android:id="@+id/tvInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Personal Information of Student"
android:textSize="20sp"
android:gravity="center_horizontal"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:textColor="@android:color/holo_red_light"/>
<EditText android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter you name"
android:ems="10"
android:inputType="textPersonName"
android:textSize="18sp"
android:layout_marginTop="50dp"
android:layout_below="@+id/tvInfo"/>
<EditText android:id="@+id/dob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Date of Birth"
android:ems="10"
android:inputType="date"
android:textSize="18sp"
android:layout_below="@+id/name"
android:layout_marginTop="25dp"/>
<EditText android:id="@+id/city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your City"
android:ems="10"
android:inputType="textCapCharacters"
android:textSize="18sp"
android:layout_below="@+id/dob"
android:layout_marginTop="25dp"/>
<EditText android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Email ID"
android:ems="10"
android:inputType="textEmailAddress"
android:textSize="18sp"
android:layout_below="@+id/city"
android:layout_marginTop="25dp"/>
<EditText android:id="@+id/contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Contact number"
android:ems="10"
android:inputType="date"
android:textSize="18sp"
android:layout_below="@+id/email"
android:layout_marginTop="25dp"/>
<Button android:id="@+id/btnSubmit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/contact"
android:layout_marginTop="50dp"
android:text="Submit"
android:textSize="18sp"
android:onClick="displayData"/>
</RelativeLayout>
Java file
package com.example.studentpersonalinfoapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
dob = findViewById(R.id.dob);
city = findViewById(R.id.city);
email = findViewById(R.id.email);
contact = findViewById(R.id.contact);
submit = findViewById(R.id.btnSubmit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String n = name.getText().toString();
String d = dob.getText().toString();
String ci = city.getText().toString();
String e = email.getText().toString();
String c = contact.getText().toString();
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"
android:padding="20dp">
<TextView android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Showing AutoCompleteTextView for Serach Engine"
android:gravity="center"
android:layout_marginTop="50dp"
android:textSize="20sp"/>
<AutoCompleteTextView android:id="@+id/auto_complete"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="20sp"
android:hint="Enter here"
android:layout_below="@id/textView"
android:layout_marginTop="30dp"/>
</RelativeLayout>
Java file
package com.example.searchengineautoctextview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autotextview = findViewById(R.id.auto_complete);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, search_engines);
autotextview.setThreshold(1);
autotextview.setAdapter(adapter);
}
}
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"
android:padding="20dp">
<TextView android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Showing AutoCompleteTextView for \nSIXTH SEMESTER
SUBJECTS"
android:gravity="center"
android:layout_marginTop="50dp"
android:textSize="20sp"/>
<AutoCompleteTextView android:id="@+id/auto_complete"
android:layout_width="match_parent"
android:layout_height="50dp"
android:textSize="20sp"
android:hint="Enter subject here"
android:layout_below="@+id/textView"
android:layout_marginTop="30dp"/>
</RelativeLayout>
Java file
package com.example.sixthsemautoctextview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
AutoCompleteTextView autotextview;
String search_engines[] = {"Management", "Programming with Python",
"Mobile Application Development",
"Emerging Trends in Computer & IT", "Web
Based Application Development Using PHP",
"Entrepreneurship Development", "Capstone
Project"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autotextview = findViewById(R.id.auto_complete);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, search_engines);
autotextview.setThreshold(2);
autotextview.setAdapter(adapter);
}
}
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"
android:padding="20dp">
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="ToggleButton"
android:textOn="ON"
android:textOff="OFF"
android:textSize="20sp"
android:layout_centerInParent="true"/>
<TextView android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/toggleButton"
android:text="Bluetooth is OFF"
android:gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="@color/colorAccent"/>
</RelativeLayout>
Java file
package com.example.togglebuttonbluetooth;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;
ToggleButton toggleButton;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toggleButton = findViewById(R.id.toggleButton);
textView = findViewById(R.id.textView);
toggleButton.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked)
{
textView.setText("Bluetooth is " +
toggleButton.getTextOn());
}
else
{
textView.setText("Bluetooth is " +
toggleButton.getTextOff());
}
}
});
}
}
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="10dp"
android:gravity="center"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="First Number"
android:gravity="center"
style="@android:style/TextAppearance.Large"/>
<EditText android:id="@+id/etNum1"
android:layout_width="200dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Enter number 1"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@id/tv1"/>
<TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="Second Number"
android:gravity="center"
android:layout_below="@id/tv1"
style="@android:style/TextAppearance.Large"/>
<EditText android:id="@+id/etNum2"
android:layout_width="200dp"
android:layout_height="50dp"
android:ems="10"
android:hint="Enter number 2"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/tv2"
android:layout_below="@id/etNum1"/>
<Button android:id="@+id/btnPlus"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="+"
android:textSize="26sp"
android:layout_below="@id/tv2"
android:layout_marginTop="30dp"
android:layout_marginLeft="50dp"
android:onClick="add"/>
<Button android:id="@+id/btnMinus"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="-"
android:textSize="26sp"
android:layout_below="@id/tv2"
android:layout_toRightOf="@id/btnPlus"
android:layout_marginTop="30dp"
android:onClick="subtract"/>
<Button android:id="@+id/btnMul"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="*"
android:textSize="26sp"
android:layout_below="@id/tv2"
android:layout_toRightOf="@id/btnMinus"
android:layout_marginTop="30dp"
android:onClick="multiply"/>
<Button android:id="@+id/btnDiv"
android:layout_width="70dp"
android:layout_height="70dp"
android:text="/"
android:textSize="26sp"
android:layout_below="@id/tv2"
android:layout_toRightOf="@id/btnMul"
android:layout_marginTop="30dp"
android:onClick="divide"/>
<TextView android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnPlus"
android:textSize="26sp"
android:layout_marginTop="50dp"/>
</RelativeLayout>
Java file
package com.example.calculator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNum1 = findViewById(R.id.etNum1);
etNum2 = findViewById(R.id.etNum2);
btnPlus = findViewById(R.id.btnPlus);
btnMinus = findViewById(R.id.btnMinus);
btnMul = findViewById(R.id.btnMul);
btnDiv = findViewById(R.id.btnDiv);
tvResult = findViewById(R.id.tvResult);
}
double n1 = Double.parseDouble(etNum1.getText().toString());
double n2 = Double.parseDouble(etNum2.getText().toString());
double result = n1 + n2;
tvResult.setText("Addition is: " + result);
}
double n1 = Double.parseDouble(etNum1.getText().toString());
double n2 = Double.parseDouble(etNum2.getText().toString());
double result = n1 - n2;
tvResult.setText("Subtraction is: " + result);
}
double n1 = Double.parseDouble(etNum1.getText().toString());
double n2 = Double.parseDouble(etNum2.getText().toString());
double result = n1 * n2;
tvResult.setText("Multiplication is: " + result);
}
double n1 = Double.parseDouble(etNum1.getText().toString());
double n2 = Double.parseDouble(etNum2.getText().toString());
double result = n1 / n2;
tvResult.setText("Division is: " + result);
}
}
13 Develop an android application to create a login form for a social
networking site
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:background="#495B8F"
android:padding="20dp"
tools:context=".MainActivity">
<TextView android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="F A C E B O O K"
android:gravity="center"
android:textSize="40sp"
android:textStyle="bold"
android:layout_marginTop="40dp"
android:textColor="@android:color/white"/>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@id/logo"
android:layout_marginTop="30dp"
android:background="@android:color/white"
android:fontFamily="monospace"
android:hint="Email or phone number"
android:padding="10dp"
android:textSize="22sp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@id/username"
android:background="@android:color/white"
android:fontFamily="monospace"
android:hint="Password"
android:padding="10dp"
android:layout_marginTop="20dp"
android:textSize="22sp" />
<Button android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/password"
android:layout_marginTop="30dp"
android:text="Log In"
android:background="#6D9ADD"
android:textColor="@android:color/white"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Forgot Password?"
android:textColor="@android:color/white"
android:layout_below="@id/btnLogin"
android:layout_marginTop="10dp"
android:textSize="16sp"/>
</RelativeLayout>
Java file
package com.example.socialnetworkingapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
<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="20dp"
tools:context=".MainActivity">
<TextView android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="R C P P"
android:gravity="center"
android:textSize="40sp"
android:textStyle="bold"
android:layout_marginTop="40dp"/>
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@id/logo"
android:layout_marginTop="30dp"
android:background="@android:color/white"
android:fontFamily="monospace"
android:hint="Enrollment number"
android:padding="10dp"
android:textSize="22sp" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="@id/username"
android:background="@android:color/white"
android:fontFamily="monospace"
android:hint="Password"
android:padding="10dp"
android:layout_marginTop="20dp"
android:textSize="22sp" />
<Button android:id="@+id/btnLogin"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/password"
android:layout_marginTop="30dp"
android:text="Log In"
android:background="#6D9ADD"
android:textColor="@android:color/white"
android:textSize="18sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Forgot Password?"
android:layout_below="@id/btnLogin"
android:layout_marginTop="10dp"
android:textSize="16sp"/>
</RelativeLayout>
Java file
package com.example.studentregistrationapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/msg"
style="@style/TextAppearance.AppCompat.Large"
android:layout_margin="10dp"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/android"
style="@style/TextAppearance.AppCompat.Headline"/>
<CheckBox
android:id="@+id/chkJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/java"
style="@style/TextAppearance.AppCompat.Headline"/>
<CheckBox
android:id="@+id/chkPhp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/php"
style="@style/TextAppearance.AppCompat.Headline"/>
<CheckBox
android:id="@+id/chkCpp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cpp"
style="@style/TextAppearance.AppCompat.Headline"/>
<CheckBox
android:id="@+id/chkC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/c"
style="@style/TextAppearance.AppCompat.Headline"/>
<Button android:id="@+id/btnDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display"
android:layout_marginTop="20dp"
android:onClick="showSelected"/>
</LinearLayout>
Java file
package com.example.checkboxdemo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chkAndroid = findViewById(R.id.chkAndroid);
chkJava = findViewById(R.id.chkJava);
chkPhp = findViewById(R.id.chkPhp);
chkCpp = findViewById(R.id.chkCpp);
chkC = findViewById(R.id.chkC);
}
if(chkAndroid.isChecked())
selected += "Android";
if(chkJava.isChecked())
selected += "\nJava";
if(chkPhp.isChecked())
selected += "\nPHP";
if(chkCpp.isChecked())
selected += "\nCPP";
if(chkC.isChecked())
selected += "\nC";
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CheckBoxApp</string>
<string name="msg">Select your favourite programming languages</string>
<string name="android">Android</string>
<string name="java">Java</string>
<string name="php">PHP</string>
<string name="cpp">CPP</string>
<string name="c">C</string>
</resources>
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="20dp"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Single Radio Button"
android:textSize="20sp" />
<RadioButton
android:id="@+id/radio1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button 1"
android:textSize="18dp"
android:textStyle="bold"/>
<RadioButton
android:id="@+id/radio2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button 2"
android:textSize="18dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/black"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Radio button inside RadioGroup"
android:textSize="20sp" />
<RadioGroup android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="18dp"
android:textStyle="bold" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:textSize="18dp"
android:textStyle="bold" />
</RadioGroup>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Show Selected"
android:onClick="showSelected"/>
</LinearLayout>
Java file
package com.example.radiobuttonapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
radio1 = findViewById(R.id.radio1);
radio2 = findViewById(R.id.radio2);
radioMale = findViewById(R.id.radioMale);
radioFemale = findViewById(R.id.radioFemale);
radioGroup = findViewById(R.id.radioGroup);
}
if(radio1.isChecked())
selected += "Radio Button 1\n";
if(radio2.isChecked())
selected += "Radio Button 2\n";
RadioButton selectedRadio =
findViewById(radioGroup.getCheckedRadioButtonId());
selected += selectedRadio.getText().toString();
Toast.makeText(MainActivity.this, selected,
Toast.LENGTH_SHORT).show();
}
}
17 Develop an android application to display horizontal and circular
progress bar
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">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="23dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />
<ProgressBar
android:id="@+id/progressBar_cyclic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:minWidth="50dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
android:layout_below="@+id/progressBar"/>
</RelativeLayout>
Java file
package com.example.circularprogressbar;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressStatus += 1;
handler.post(new Runnable() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try {
Thread.sleep(200);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
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">
<ListView android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Java file
package com.example.programminglanguageslistview;
import android.support.v7.app.AppCompatActivity;
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;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.list_view);
listView.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int
position, long id) {
Toast.makeText(MainActivity.this,
((TextView)view).getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
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"
tools:context=".MainActivity">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="68dp"
android:text="Pizza"/>
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Coffee" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="28dp"
android:text="Burger"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="144dp"
android:layout_marginTop="184dp"
android:text="Order" />
</LinearLayout>
Java file
package com.example.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
CheckBox pizza,coffe,burger;
Button buttonOrder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pizza=(CheckBox)findViewById(R.id.checkBox);
coffe=(CheckBox)findViewById(R.id.checkBox2);
burger=(CheckBox)findViewById(R.id.checkBox3);
buttonOrder=(Button)findViewById(R.id.button);
buttonOrder.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
int totalamount = 0;
StringBuilder result = new StringBuilder();
result.append("Selected Items:");
if(pizza.isChecked()){
result.append("\nPizza 100Rs");
totalamount += 100;
}
if(coffe.isChecked()){
result.append("\nCoffe 50Rs");
totalamount += 50;
}
if(burger.isChecked()){
result.append("\nBurger 120Rs");
totalamount += 120;
}
result.append("\nTotal: "+totalamount+"Rs");
Toast.makeText(getApplicationContext(), result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}
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"
android:padding="20dp">
<EditText android:id="@+id/etDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginTop="100dp"/>
<Button android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Date"
android:layout_toRightOf="@+id/etDate"
android:layout_marginTop="100dp"
android:onClick="showDatePicker"/>
<EditText android:id="@+id/etTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_below="@+id/etDate"/>
<Button android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Time"
android:layout_toRightOf="@+id/etTime"
android:layout_below="@+id/btnDate"
android:onClick="showTimePicker"/>
</RelativeLayout>
Java file
package com.example.datetimepickerdialog;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TimePicker;
import java.util.Calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etDate = findViewById(R.id.etDate);
etTime = findViewById(R.id.etTime);
btnDate = findViewById(R.id.btnDate);
btnTime = findViewById(R.id.btnTime);
}
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int
minute) {
etTime.setText(hourOfDay + " : " + minute);
}
}, mHour,mMinute, false);
timePickerDialog.show();
}
}
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="Hello World!" />
</RelativeLayout>
Java file
package com.example.activitylifecycle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("MainActivity", "onCreate() called");
}
@Override
protected void onStart() {
super.onStart();
Log.d("MainActivity", "onStart() called");
}
@Override
protected void onResume() {
super.onResume();
Log.d("MainActivity", "onResume() called");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("MainActivity", "onRestart() called");
}
@Override
protected void onPause() {
super.onPause();
Log.d("MainActivity", "onPause() called");
}
@Override
protected void onStop() {
super.onStop();
Log.d("MainActivity", "onStop() called");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("MainActivity", "onDestroy() called");
}
}
22 Develop an android application to calculate Factorial of a number
using Activity Intents
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"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="20dp">
<EditText android:id="@+id/etNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the number"
android:inputType="number"
android:layout_marginTop="50dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Factorial"
android:onClick="displayFactorial"/>
</LinearLayout>
Java file
package com.example.factorialintent;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
EditText etNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etNumber = findViewById(R.id.etNumber);
}
activity_factorial.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=".FactorialActivity"
android:padding="20dp">
<TextView android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Factorial of number is"
style="@style/TextAppearance.AppCompat.Large"/>
</RelativeLayout>
FactorialActivity.java
package com.example.factorialintent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_factorial);
Bundle b = getIntent().getExtras();
int no = Integer.parseInt(b.getString("number"));
long f=1;
tv = findViewById(R.id.tv);
tv.setText("Factorial of " + no + " is " + f);
}
}
Xml file
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastreceiverdemo">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
</application>
</manifest>
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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
Java file
package com.example.broadcastreceiverdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
MyBroadcastReceiver.java
package com.example.broadcastreceiverdemo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.widget.Toast;
@Override
public void onReceive(Context context, Intent intent) {
if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Toast.makeText(context, "Boot Completed", Toast.LENGTH_SHORT).show();
}
if(ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
Toast.makeText(context, "Connectivity Changed",
Toast.LENGTH_SHORT).show();
}
}
}
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:padding="10dp">
<TextView android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</ScrollView>
MainActivity.java
package com.example.sensorlistexample;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.util.List;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
String sensorInfo = "";
for(Sensor s : sensorList) {
sensorInfo += s.getName() + "\n";
}
tv.setText(sensorInfo);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cameraapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="20dp">
<ImageView android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
android:text="Hello World!"
android:background="@drawable/border_image_view"
android:layout_gravity="center_horizontal"/>
<Button android:id="@+id/btnCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Capture"
android:layout_marginTop="20dp"
android:onClick="captureImage"/>
</LinearLayout>
MainActivity.java
package com.example.cameraapp;
import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageView);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_CODE_CAMERA) {
if(resultCode == RESULT_OK) {
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
else {
Toast.makeText(getApplicationContext(), "Cancelled by user",
Toast.LENGTH_SHORT).show();
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rcppp.bluetoothapp">
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.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"
tools:context=".MainActivity"
android:padding="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bluetooth"
android:textSize="20sp"
android:textStyle="bold"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On"
android:onClick="turnOn"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Visible"
android:onClick="getVisible"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="List Devices"
android:onClick="listDevices"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn Off"
android:onClick="turnOff"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Paired Devices"
android:textColor="@android:color/holo_red_dark"/>
<ListView android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
package com.example.bluetoothapp;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ba = BluetoothAdapter.getDefaultAdapter();
listView = findViewById(R.id.listView);
}
if(!ba.isEnabled()) {
Intent intentOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intentOn, 0);
Toast.makeText(getApplicationContext(), "Turned ON",
Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(getApplicationContext(), "Already ON",
Toast.LENGTH_SHORT).show();
}
}
for(BluetoothDevice b : pairedDevices) {
list.add(b.getName());
}
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1, list);
listView.setAdapter(adapter);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sqlitedbapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity"
android:padding="20dp"
android:orientation="vertical">
<EditText android:id="@+id/etRN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter roll no" />
<EditText android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter name" />
<Button android:id="@+id/btnAddStudent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Student"
android:onClick="addNewStudent"/>
<TextView android:id="@+id/tvInfo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="22sp"
android:padding="10dp"/>
</LinearLayout>
MainActivity.java
package com.example.sqlitedbapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import java.util.List;
DatabaseHelper databaseHelper;
EditText etRN, etName;
TextView tvInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etRN = findViewById(R.id.etRN);
etName = findViewById(R.id.etName);
tvInfo = findViewById(R.id.tvInfo);
databaseHelper = new DatabaseHelper(MainActivity.this);
}
public void addNewStudent(View view) {
int rn = Integer.parseInt(etRN.getText().toString());
String name = etName.getText().toString();
databaseHelper.addStudent(rn, name);
displayAllStudents();
}
for(Student s : studentList) {
data += s.getRollno() + ", " + s.getName() + "\n";
}
tvInfo.setText(data);
}
}
DatabaseHelper.java
package com.example.sqlitedbapp;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME + "( " + COLUMN_ID + " INTEGER
PRIMARY KEY AUTOINCREMENT, " + COLUMN_ROLL_NO + " TEXT"+", " + COLUMN_NAME + ");";
try {
db.execSQL(query);
}
catch(Exception e) {
e.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
while (c.moveToNext()) {
rn = c.getInt(c.getColumnIndex(COLUMN_ROLL_NO));
n = c.getString(c.getColumnIndex(COLUMN_NAME));
list.add(new Student(rn, n));
}
db.close();
return list;
}
SQLiteDatabase db = getWritableDatabase();
db.execSQL("DELETE FROM " + TABLE_NAME + " WHERE " + COLUMN_ROLL_NO + "=" +
rollno);
}
}
Student.java
package com.example.sqlitedbapp;
public class Student {
int rollno;
String name;
public Student(int rollno, String name) {
this.rollno = rollno;
this.name = name;
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login Form"
android:layout_marginTop="100dp"
android:textSize="35sp"
android:textColor="@color/colorAccent"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:layout_marginTop="100dp"
android:textSize="20sp"/>
<EditText android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="20sp"/>
<EditText android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
<TextView android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_red_dark"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="login"/>
</LinearLayout>
MainActivity.java
package com.example.loginapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
EditText etUsername,etPassword;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = findViewById(R.id.etUsername);
etPassword = findViewById(R.id.etPassword);
tv = findViewById(R.id.tv);
}
if(etUsername.getText().toString().equals("admin") &&
etPassword.getText().toString().equals("1234")) {
tv.setText("Login Successful");
}
else {
tv.setText("");
Toast.makeText(MainActivity.this, "Login fail.",
Toast.LENGTH_SHORT).show();
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginvalidateapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.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"
tools:context=".MainActivity"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login Form"
android:layout_marginTop="100dp"
android:textSize="35sp"
android:textColor="@color/colorAccent"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:layout_marginTop="100dp"
android:textSize="20sp"/>
<EditText android:id="@+id/etUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textSize="20sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="20sp"/>
<EditText android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textSize="20sp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:onClick="login" />
</LinearLayout>
MainActivity.java
package com.example.loginvalidateapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
EditText etUsername,etPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = findViewById(R.id.etUsername);
etPassword = findViewById(R.id.etPassword);
}
if(uname.equals("") || pwd.equals("")) {
return "Plz enter both username and password";
}