Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Mad Record

Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

BHARATHI WOMENS ARTS AND SCIENCE COLLEGE

(An ISO 9001 – 2000 CERTIFIED INSTITUTION)


THATCHUR, KALLAKURICHI- 606 202.

DEPARTMENT OF COMPUTER SCIENCE


CERTIFICATE

Certified that this is the bonafide record of practical done by


……………………………. Register Number ………………………… year/Branch
………………………. In the lab ……………………………. During the academic
year…………………………………………

Faculty incharge Head of the Department

Submitted for the University Practical Examination held on …………………….

External Examiner External Examiner


SUB.NAME: _____________________ SUB.CODE: ___________

S.NO DATE CONTENT PAGE NO SIGNATURE

1 SIMPLE ANDROID
APPLICATION.

2
WORKING WITH ACTIVITY

3 WORKING WITH
FRAGMENTS

4 UI CONTROLS (TEXT, EDIT


TEXT, BUTTON, RADIO
BUTTON)

5 UI CONTROLS (CHECK BOX,


AND LAYOUT, IMAGE
BUTTON, TOGGLE BUTTON)

6 UI CONTROLS (RATING BAR,


LIST VIEW, GALLERY)

7 CRUD OPERATIONS USING


SQLITE DB

8
EMAILING

9
TELEPHONY

SMS
10
SIMPLE ANDROID APPLICATION

Activity_main.xml [code]

<?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:id="@+id/RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textview1"
android:layout_width="384dp"
android:layout_height="83dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="14dp"
android:layout_marginEnd="13dp"
android:layout_marginBottom="572dp"
android:fontFamily="cursive"
android:text="Creating Simple Application"
android:textAlignment="center"
android:textAllCaps="false"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="#E91E63"
android:textSize="34sp"
android:typeface="sans"
tools:visibility="visible" />
<Switch
android:id="@+id/switch1"
android:layout_width="265dp"
android:layout_height="69dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="65dp"
android:layout_marginTop="184dp"
android:layout_marginEnd="79dp"
android:layout_marginBottom="478dp"
android:fontFamily="serif"
android:showText="true"
android:splitTrack="true"
android:text="NightMode" />
</RelativeLayout>

MainActivity.java

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Switch;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.RelativeLayout);
Switch sw1=findViewById(R.id.switch1);
sw1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(sw1.isChecked()){
relativeLayout.setBackgroundColor(Color.DKGRAY);
}
else{
relativeLayout.setBackgroundColor(Color.WHITE);
}

});

}
Output
WORKING WITH ACTIVITY
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:id="@+id/r_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="215dp"
android:layout_height="66dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="97dp"
android:layout_marginEnd="98dp"
android:layout_marginBottom="587dp"
android:text="WORKING WITH ACTIVITIES"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#077E73"
android:textSize="24sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnMad"
android:layout_width="295dp"
android:layout_height="105dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="58dp"
android:layout_marginEnd="57dp"
android:layout_marginBottom="330dp"
android:text="Mobile Application Development" />
<TextView
android:id="@+id/textView"
android:layout_width="167dp"
android:layout_height="41dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="123dp"
android:layout_marginEnd="121dp"
android:layout_marginBottom="497dp"
android:text="Select Subject"
android:textAlignment="center"
android:textColor="#E91E63"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnSpm"
android:layout_width="285dp"
android:layout_height="93dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="61dp"
android:layout_marginEnd="65dp"
android:layout_marginBottom="219dp"
android:text="Software Project Management" />

</RelativeLayout>

MainActivity.java

package com.example.wwalab2;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.content.Intent;
public class MainActivity extends AppCompatActivity {
Button btnMad,btnSpm;
RelativeLayout rLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rLayout = (RelativeLayout) findViewById(R.id.r_layout);
btnMad = (Button) findViewById(R.id.btnMad);
btnSpm = (Button) findViewById(R.id.btnSpm);
btnMad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent1=new Intent(getApplicationContext(),Activity2Mad.class);
startActivity(indent1);
}});
btnSpm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent2=new Intent(getApplicationContext(),Activity3SPM.class);
startActivity(indent2);
}});
}
}

activity_activity2Mad.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:id="@+id/r_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity2Mad">

<TextView
android:id="@+id/textView2"
android:layout_width="300dp"
android:layout_height="126dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="53dp"
android:layout_marginTop="237dp"
android:layout_marginEnd="57dp"
android:layout_marginBottom="368dp"
android:text="Mobile application development is the process of creating software
applications that run on a mobile device."
android:textAlignment="viewStart"
android:textColor="#009688"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/textView3"
android:layout_width="251dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="77dp"
android:layout_marginEnd="83dp"
android:layout_marginBottom="562dp"
android:text="MOBILE APPLICATION DEVELOPMENT"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#673AB7"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>

Activity2Mad.java

package com.example.wwalab2;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.content.Intent;
public class Activity2Mad extends AppCompatActivity {
Button btnHome;
RelativeLayout rlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2_mad);
rlayout = (RelativeLayout) findViewById(R.id.r_Layout);
btnHome = (Button) findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent=new Intent(getApplicationContext(), MainActivity.class);
startActivity(indent);
}
});
}
}

activity_activity3Spm.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:id="@+id/r_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity3SPM">
<TextView
android:id="@+id/textView4"
android:layout_width="257dp"
android:layout_height="83dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="77dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="76dp"
android:layout_marginBottom="578dp"
android:text="SOFWARE PROJECT MANAGEMENT"
android:textAlignment="center"
android:textColor="#E91E63"
android:textSize="24sp"
android:textStyle="bold" />

<TextView
android:id="@+id/textView5"
android:layout_width="334dp"
android:layout_height="122dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="39dp"
android:layout_marginBottom="421dp"
android:text="Software Project Management (SPM) is a proper way of planning and
leading software projects."
android:textAlignment="textStart"
android:textColor="#673AB7"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="156dp"
android:layout_marginBottom="315dp"
android:text="Go Home" />
</RelativeLayout>

Activity_activity3_spm.xml

package com.example.wwalab2;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.RelativeLayout;
import android.content.Intent;
public class Activity3SPM extends AppCompatActivity {
Button btnHome;
RelativeLayout rlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity3_spm);
rlayout = (RelativeLayout) findViewById(R.id.r_layout);
btnHome=(Button) findViewById(R.id.btnHome);
btnHome.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent indent=new Intent(getApplicationContext(), MainActivity.class);
startActivity(indent);
}
});
}
}
WORKING WITH FRAGMENTS
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"
android:orientation="horizontal"
tools:context=".MainActivity">
<fragment
android:layout_height="match_parent"
android:layout_width="350px"
class="com.example.fragdemo.ListMenuFragment"
android:id="@+id/fragment"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragdemo.DetailsFragment"
android:id="@+id/fragment2"/>
</LinearLayout>

Listitems_info.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/list" />
</LinearLayout>

Details_info.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0079D6">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_marginTop="200px"
android:layout_marginLeft="200px"
android:id="@+id/Name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200px"
android:textColor="#ffffff"
android:id="@+id/Location"/>
</LinearLayout>

DetailsFraments.java

package com.example.fragdemo;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class DetailsFragment extends Fragment {


TextView name,location;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view = inflater.inflate(R.layout.details_info, container, false);
name = (TextView)view.findViewById(R.id.Name);
location = (TextView)view.findViewById(R.id.Location);
return view;
}
public void change(String uname, String ulocation){
name.setText(uname);
location.setText(ulocation);
}
}

ListMenuFragment.java

package com.example.fragdemo;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListMenuFragment extends ListFragment {


String[] users = new String[] { "Devi","Ishwarya","Pavithra","Radha" };
String[] location = new String[]{"Thatchur","Kallakurichi","Thatchur","Eamaper"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view =inflater.inflate(R.layout.listitems_info, container, false);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, users);
setListAdapter(adapter);
return view;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
DetailsFragment txt =
(DetailsFragment)getFragmentManager().findFragmentById(R.id.fragment2);
txt.change("Name: "+ users[position],"Location : "+ location[position]);
getListView().setSelector(android.R.color.holo_blue_dark);
}
}

MainActivity.java

package com.example.fragdemo;
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);
}
}
UI CONTROLS (TEXT, EDIT TEXT, BUTTON, RADIO BUTTON)

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:id="@+id/lnrlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:textAlignment="center"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="81dp"
android:text="Radio Button Group Example"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#3F51B5"
android:textSize="18sp"
android:textStyle="bold" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="309dp">
<RadioButton
android:id="@+id/red"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_weight="1"
android:text="RED"
android:textAllCaps="true"
android:textColor="#F44336"
android:textSize="24sp"
android:textStyle="bold|italic" />
<RadioButton
android:id="@+id/blue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="BLUE"
android:textColor="#3F51B5"
android:textSize="24sp"
android:textStyle="bold|italic" />
<RadioButton
android:id="@+id/green"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GREEN"
android:textColor="#4CAF50"
android:textSize="24sp"
android:textStyle="bold|italic" />
</RadioGroup>
<Button
android:id="@+id/btnSumbit"
android:layout_width="match_parent"
android:layout_height="102dp"
android:text="Set as BG Color"
android:textColor="#E91E63"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtDisplay"
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="#FFEB3B"
android:text="TextView"
android:textSize="24sp" />
</LinearLayout>
MainActivity.java

package com.example.radiobutton;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
RadioButton red,blue,green;
Button btnsubmit;
TextView txtView;
LinearLayout lnrlayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
red=(RadioButton )findViewById(R.id.red);
blue=(RadioButton )findViewById(R.id.blue);
green = (RadioButton)findViewById(R.id.green);
btnsubmit=(Button)findViewById(R.id.btnSumbit);
txtView = (TextView)findViewById(R.id.txtDisplay);
lnrlayout = (LinearLayout)findViewById(R.id.lnrlayout);
btnsubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(red.isChecked())
{
txtView.setText("You've Selected RED");
lnrlayout.setBackgroundColor(Color.RED);
}
if(blue.isChecked())
{
txtView.setText("You've seleceted BLUE");
lnrlayout.setBackgroundColor(Color.BLUE);
}
if(green.isChecked())
{
txtView.setText("You've Selected Green");
lnrlayout.setBackgroundColor(Color.GREEN);
}
}
});
}
}
UI Controls (Check Box, and Layout, Image Button, Toggle Button)

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:id="@+id/r_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ToggleButton
android:id="@+id/toggle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="35dp"
android:layout_marginBottom="564dp"
android:checked="false"
android:text="ON" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="59dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="61dp"
android:layout_marginEnd="63dp"
android:layout_marginBottom="634dp"
android:text="UI Controls - CheckBox,Toggle,Image Button"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#AF1010"
android:textStyle="bold" />
<CheckBox
android:id="@+id/chkmad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="239dp"
android:layout_marginBottom="469dp"
android:text="MAD"
android:textColor="#009688" />
<CheckBox
android:id="@+id/chkspm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="241dp"
android:layout_marginBottom="416dp"
android:text="SPM"
android:textColor="#009688" />
<CheckBox
android:id="@+id/chkhr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="251dp"
android:layout_marginBottom="361dp"
android:text="HR"
android:textColor="#009688" />
<ImageButton
android:id="@+id/ShareBtn"
android:layout_width="81dp"
android:layout_height="66dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="156dp"
android:layout_marginEnd="173dp"
android:layout_marginBottom="265dp"
android:contentDescription="@android:string/copyUrl"
app:srcCompat="@android:drawable/ic_menu_share" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="144dp"
android:layout_marginBottom="580dp"
android:text="DarkTheme" />
<TextView
android:id="@+id/TxtShow"
android:layout_width="207dp"
android:layout_height="101dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="96dp"
android:layout_marginEnd="108dp"
android:layout_marginBottom="117dp"
android:textColor="#FF5722" />
</RelativeLayout>
MainActivity.java

package com.example.uicontrolsii;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
CheckBox mad,spm,hr;
TextView txtshow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ToggleButton tb1 = (ToggleButton)findViewById(R.id.toggle1);
final RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.r_layout);
txtshow = (TextView)findViewById(R.id.TxtShow);
mad=(CheckBox)findViewById(R.id.chkmad);
spm=(CheckBox)findViewById(R.id.chkspm);
hr=(CheckBox)findViewById(R.id.chkhr);
ImageButton btnshare = (ImageButton)findViewById(R.id.ShareBtn);
tb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
relativeLayout.setBackgroundResource(R.color.black);
}
else {
relativeLayout.setBackgroundResource(R.color.white);
}
}
});
btnshare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String result = "Selected Courses";
if(mad.isChecked() ){
result += "\nMAD";
}
if(spm.isChecked() ){
result += "\nSPM";
}
if(hr.isChecked() ){
result += "\nHR";
}
txtshow.setText(":" + result);
}
});
}
}
UI CONTROLS (RATING BAR, LIST VIEW, GALLERY)

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"
android:orientation="horizontal"
tools:context=".MainActivity">
<fragment
android:layout_height="match_parent"
android:layout_width="350px"
class="com.example.fragdemo.ListMenuFragment"
android:id="@+id/fragment"/>
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragdemo.DetailsFragment"
android:id="@+id/fragment2"/>
</LinearLayout>

Listitems_info.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/list" />
</LinearLayout>

Details_info.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0079D6">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_marginTop="200px"
android:layout_marginLeft="200px"
android:id="@+id/Name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="200px"
android:textColor="#ffffff"
android:id="@+id/Location"/>

<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="291dp"
android:layout_height="75dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="200dp"
android:numStars="5"
android:rating="3.5" />

<Button
android:id="@+id/btnGet"
android:layout_width="104dp"
android:layout_height="wrap_content"
android:layout_below="@+id/ratingBar1"
android:layout_alignLeft="@+id/ratingBar1"
android:layout_marginLeft="60dp"
android:layout_marginTop="30dp"
android:text="Get Rating" />

<TextView
android:id="@+id/textview1"
android:layout_width="223dp"
android:layout_height="69dp"
android:layout_below="@+id/btnGet"
android:layout_alignLeft="@+id/btnGet"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:textStyle="bold" />

</LinearLayout>

DetailsFraments.java

package com.example.fragdemo;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Button;
import android.widget.RatingBar;
public class DetailsFragment extends Fragment {
TextView name,location;
private RatingBar rBar;
private TextView tView;
private Button btn;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view = inflater.inflate(R.layout.details_info, container, false);
name = (TextView)view.findViewById(R.id.Name);
location = (TextView)view.findViewById(R.id.Location);
rBar = (RatingBar)view.findViewById(R.id.ratingBar1);
tView = (TextView)view.findViewById(R.id.textview1);
btn = (Button)view.findViewById(R.id.btnGet);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int noofstars = rBar.getNumStars();
float getrating = rBar.getRating();
tView.setText("Rating: "+getrating+"/"+noofstars);
}
});
return view;
}
public void change(String uname, String ulocation){
name.setText(uname);
location.setText(ulocation);
}
}

ListMenuFragment.java

package com.example.fragdemo;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListMenuFragment extends ListFragment {
String[] users = new String[] { "Devi","Ishwarya","Pavithra","Radha" };
String[] location = new String[]{"Thatchur","Kallakurichi","Thatchur","Eamaper"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View view =inflater.inflate(R.layout.listitems_info, container, false);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, users);
setListAdapter(adapter);
return view;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
DetailsFragment txt =
(DetailsFragment)getFragmentManager().findFragmentById(R.id.fragment2);
txt.change("Name: "+ users[position],"Location : "+ location[position]);
getListView().setSelector(android.R.color.holo_blue_dark);
}
}

MainActivity.java

package com.example.fragdemo;
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);
}
}
Output
CRUD OPERATIONS USING SQLITE DB
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" >
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="72dp"
android:ems="10"
android:gravity="center"
android:hint="Enter Name Student Name" />
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_marginTop="18dp"
android:ems="10"
android:gravity="center"
android:hint="Enter Phone Number Here"
android:inputType="phone" />
<EditText
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_marginTop="24dp"
android:ems="10"
android:gravity="center"
android:hint="Enter Course Here" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Insert" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Edit " />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="Show all " />
<TextView
android:id="@+id/textView5"
android:layout_width="292dp"
android:layout_height="54dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="76dp"
android:layout_marginTop="15dp"
android:layout_marginEnd="43dp"
android:layout_marginBottom="534dp"
android:text="Student Information Application"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#673AB7"
android:textSize="24sp"
android:textStyle="bold" />
</RelativeLayout>
Activity_edit_data.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=".EditDataActivity">
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="127dp"
android:gravity="center"
android:text="Edit Record Id = "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview1"
android:layout_centerHorizontal="true"
android:ems="10"
android:hint="Name Show Here"
android:gravity="center"
android:layout_marginTop="20dp" />
<EditText
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="phone"
android:hint="Phone Number Show Here"
android:gravity="center" />
<EditText
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="Subject Show Here"
android:gravity="center" />
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Show Next Record" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button1"
android:layout_centerHorizontal="true"
android:text="Show Previous Record" />
<Button
android:id="@+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:text="Update Existing Record" />
<Button
android:id="@+id/button4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button3"
android:layout_centerHorizontal="true"
android:text="Delete Existing Record" />
</RelativeLayout>
Axtivity_list_view.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=".ListViewActivity">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="361dp"
android:layout_alignParentTop="true"
android:layout_marginTop="67dp"></ListView>
</RelativeLayout>

Listviewdatalayout.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="ID = "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textViewID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_toRightOf="@+id/textView1"
android:text="UserID"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:text="Name = "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textViewNAME"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textViewID"
android:layout_toRightOf="@+id/textView2"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:text="Phone Number = "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textViewPHONE_NUMBER"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView3"
android:layout_toRightOf="@+id/textView3"
android:text="phone number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView3"
android:text="Subject = "
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
<TextView
android:id="@+id/textViewSUBJECT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView4"
android:layout_alignBottom="@+id/textView4"
android:layout_toRightOf="@+id/textView4"
android:text="subject"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#050505" />
</RelativeLayout>

MainActivity.java

package com.example.sqllite;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText GetName,GetPhoneNumber,GetSubject ;
Button Submit, EditData, DisplayData;
SQLiteDatabase SQLITEDATABASE;
String Name, PhoneNumber, Subject ;
Boolean CheckEditTextEmpty ;
String SQLiteQuery ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
GetName = (EditText)findViewById(R.id.editText1);
GetPhoneNumber = (EditText)findViewById(R.id.editText2);
GetSubject = (EditText)findViewById(R.id.editText3);
Submit = (Button)findViewById(R.id.button1);
EditData = (Button)findViewById(R.id.button2);
DisplayData = (Button)findViewById(R.id.button3);
Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DBCreate();
SubmitData2SQLiteDB();
} });
EditData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditDataActivity.class);
startActivity(intent);
} });
DisplayData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, ListViewActivity.class);
startActivity(intent);

} }); }
public void DBCreate(){
SQLITEDATABASE = openOrCreateDatabase("DemoDataBase", Context.MODE_PRIVATE,
null);
SQLITEDATABASE.execSQL("CREATE TABLE IF NOT EXISTS demoTable(id INTEGER
PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR, phone_number
VARCHAR, subject VARCHAR);");
}
public void SubmitData2SQLiteDB(){
Name = GetName.getText().toString();
PhoneNumber = GetPhoneNumber.getText().toString();
Subject = GetSubject.getText().toString();
CheckEditTextIsEmptyOrNot( Name,PhoneNumber, Subject);
if(CheckEditTextEmpty == true)
{
SQLiteQuery = "INSERT INTO demoTable (name,phone_number,subject)
VALUES('"+Name+"', '"+PhoneNumber+"', '"+Subject+"');";
SQLITEDATABASE.execSQL(SQLiteQuery);

Toast.makeText(MainActivity.this,"Data Submit Successfully",


Toast.LENGTH_LONG).show();
ClearEditTextAfterDoneTask();
}
else {
Toast.makeText(MainActivity.this,"Please Fill All the Fields",
Toast.LENGTH_LONG).show();
} }
public void CheckEditTextIsEmptyOrNot(String Name,String PhoneNumber, String subject ){
if(TextUtils.isEmpty(Name) || TextUtils.isEmpty(PhoneNumber) || TextUtils.isEmpty(Subject)){
CheckEditTextEmpty = false ;
}
else {
CheckEditTextEmpty = true ;
}
} public void ClearEditTextAfterDoneTask(){
GetName.getText().clear();
GetPhoneNumber.getText().clear();
GetSubject.getText().clear();
} }

EditDataActivity.java

package com.example.sqllite;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class EditDataActivity extends AppCompatActivity {
Button nextbutton, previousbutton, updatebutton, deletebutton;
EditText name, phoneNumber, SubJect;
SQLiteDatabase SQLITEDATABASE, SQLITEDATABASE2 ;
String GetSQliteQuery, UpdateRecordQuery, DeleteQuery ;
Cursor cursor, cursorCheckDataIsEmptyOrNot ;
TextView idtextview;
Boolean CheckEditTextEmpty;
String GetName,GetPhoneNumber,GetSubject ;
int UserID ;
String ConvertUserID ;
SQLiteHelper SQLITEHELPER;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_data);
nextbutton = (Button)findViewById(R.id.button1);
previousbutton = (Button)findViewById(R.id.button2);
updatebutton = (Button)findViewById(R.id.button3);
deletebutton = (Button)findViewById(R.id.button4);
name = (EditText)findViewById(R.id.editText1);
phoneNumber = (EditText)findViewById(R.id.editText2);
SubJect = (EditText)findViewById(R.id.editText3);
idtextview = (TextView)findViewById(R.id.textview1);
GetSQliteQuery = "SELECT * FROM demoTable" ;
SQLITEDATABASE = openOrCreateDatabase("DemoDataBase",
Context.MODE_PRIVATE, null);
cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
cursor.moveToFirst();
GetSQLiteDatabaseRecords();
nextbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (!cursor.isLast()){
cursor.moveToNext();
}
GetSQLiteDatabaseRecords();
} });
previousbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!cursor.isFirst()){
cursor.moveToPrevious();
}
GetSQLiteDatabaseRecords();
}
});
updatebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GetName = name.getText().toString();
GetPhoneNumber = phoneNumber.getText().toString();
GetSubject = SubJect.getText().toString();
ConvertUserID = idtextview.getText().toString();
UserID = Integer.parseInt(ConvertUserID);
UpdateRecordQuery = "UPDATE demoTable SET name='" + GetName + "', phone_number='"
+ GetPhoneNumber + "', subject='" + GetSubject + "' WHERE id=" + UserID + ";";
CheckEditTextIsEmptyOrNot( GetName,GetPhoneNumber, GetSubject);
if (CheckEditTextEmpty == false) {
SQLITEDATABASE.execSQL(UpdateRecordQuery);
cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
cursor.moveToPosition(UserID);
Toast.makeText(EditDataActivity.this,"Data Updated Successfully", Toast.LENGTH_LONG).show();
}else {
Toast.makeText(EditDataActivity.this,"Please Fill All the Fields", Toast.LENGTH_LONG).show();
} } });
deletebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ConvertUserID = idtextview.getText().toString();
UserID = Integer.parseInt(ConvertUserID);
DeleteQuery = "DELETE FROM demoTable WHERE id=" + UserID + ";";
SQLITEDATABASE.execSQL(DeleteQuery);
Toast.makeText(EditDataActivity.this, "Record Deleted Successfully", Toast.LENGTH_LONG).show();
cursor = SQLITEDATABASE.rawQuery(GetSQliteQuery, null);
}

});

}
public void GetSQLiteDatabaseRecords(){
idtextview.setText(cursor.getString(0));
name.setText(cursor.getString(1).toString());
phoneNumber.setText(cursor.getString(2).toString());
SubJect.setText(cursor.getString(3).toString());
}
public void CheckEditTextIsEmptyOrNot(String Name,String PhoneNumber, String subject
){
if(TextUtils.isEmpty(Name) || TextUtils.isEmpty(PhoneNumber) ||
TextUtils.isEmpty(subject)){
CheckEditTextEmpty = true ;
}
else {
CheckEditTextEmpty = false ;
}

}
ListViewActivity.java

package com.example.sqllite;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.ListView;
public class ListViewActivity extends AppCompatActivity {
SQLiteHelper SQLITEHELPER;
SQLiteDatabase SQLITEDATABASE;
Cursor cursor;
SQLiteListAdapter ListAdapter ;
ArrayList<String> ID_ArrayList = new ArrayList<String>();
ArrayList<String> NAME_ArrayList = new ArrayList<String>();
ArrayList<String> PHONE_NUMBER_ArrayList = new ArrayList<String>();
ArrayList<String> SUBJECT_ArrayList = new ArrayList<String>();
ListView LISTVIEW;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
LISTVIEW = (ListView) findViewById(R.id.listView1);
SQLITEHELPER = new SQLiteHelper(this);
}
@Override
protected void onResume() {
ShowSQLiteDBdata() ;
super.onResume();
}
private void ShowSQLiteDBdata() {
SQLITEDATABASE = SQLITEHELPER.getWritableDatabase();
cursor = SQLITEDATABASE.rawQuery("SELECT * FROM demoTable", null);
ID_ArrayList.clear();
NAME_ArrayList.clear();
PHONE_NUMBER_ArrayList.clear();
SUBJECT_ArrayList.clear();
if (cursor.moveToFirst()) {
do {
ID_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_ID)));
NAME_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_Name)));
PHONE_NUMBER_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY
_PhoneNumber)));
SUBJECT_ArrayList.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper.KEY_Subject))); }
while (cursor.moveToNext());
}
ListAdapter = new SQLiteListAdapter(ListViewActivity.this,
ID_ArrayList,
NAME_ArrayList,
PHONE_NUMBER_ArrayList,
SUBJECT_ArrayList );
LISTVIEW.setAdapter(ListAdapter);
cursor.close();
}}
SQLiteHelper.java

package com.example.sqllite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class SQLiteHelper extends SQLiteOpenHelper {
static String DATABASE_NAME="DemoDataBase";
public static final String KEY_ID="id";
public static final String TABLE_NAME="demoTable";
public static final String KEY_Name="name";
public static final String KEY_PhoneNumber="phone_number";
public static final String KEY_Subject="subject";
public SQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase database) {
String CREATE_TABLE="CREATE TABLE "+TABLE_NAME+" ("+KEY_ID+"
INTEGER PRIMARY KEY, "+KEY_Name+" VARCHAR, "+KEY_PhoneNumber+"
VARCHAR, "+KEY_Subject+" VARCHAR)";
database.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
}
SQLiteListAdapter.java
package com.example.sqllite;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class SQLiteListAdapter extends BaseAdapter {
Context context;
ArrayList<String> userID;
ArrayList<String> UserName;
ArrayList<String> User_PhoneNumber;
ArrayList<String> UserSubject ;
public SQLiteListAdapter(
Context context2,
ArrayList<String> id,
ArrayList<String> name,
ArrayList<String> phone,
ArrayList<String> subject
) {
this.context = context2;
this.userID = id;
this.UserName = name;
this.User_PhoneNumber = phone;
this.UserSubject = subject ;
}
public int getCount() {
return userID.size();
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View child, ViewGroup parent) {
Holder holder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.listviewdatalayout, null);
holder = new Holder();
holder.textviewid = (TextView) child.findViewById(R.id.textViewID);
holder.textviewname = (TextView) child.findViewById(R.id.textViewNAME);
holder.textviewphone_number = (TextView)
child.findViewById(R.id.textViewPHONE_NUMBER);
holder.textviewsubject = (TextView) child.findViewById(R.id.textViewSUBJECT);
child.setTag(holder);
} else {
holder = (Holder) child.getTag();
}
holder.textviewid.setText(userID.get(position));
holder.textviewname.setText(UserName.get(position));
holder.textviewphone_number.setText(User_PhoneNumber.get(position));
holder.textviewsubject.setText(UserSubject.get(position));
return child;
}

public class Holder {


TextView textviewid;
TextView textviewname;
TextView textviewphone_number;
TextView textviewsubject;
}
}
EMAILING
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="71dp"
android:text="Emailing Service"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#0C0C0C"
android:textStyle="bold" />
<EditText
android:id="@+id/txtTo"
android:layout_width="match_parent"
android:layout_height="63dp"
android:hint="To" />
<EditText
android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="66dp"
android:hint="Subject" />
<EditText
android:id="@+id/txtMsg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Message"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>
MainActivity.java

package com.example.emaildemo;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText eTo;
private EditText eSubject;
private EditText eMsg;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = (EditText)findViewById(R.id.txtTo);
eSubject = (EditText)findViewById(R.id.txtSub);
eMsg = (EditText)findViewById(R.id.txtMsg);
btn = (Button)findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{eTo.getText().toString()});
it.putExtra(Intent.EXTRA_SUBJECT,eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT,eMsg.getText());
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Mail App"));
}
});
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emaildemo">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="message/rfc822"/>
</intent-filter>
</activity>
</application>
</manifest>
Output
TELEPHONY
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/textView"
android:layout_width="282dp"
android:layout_height="174dp"
android:text="Android Phone Services - Call And SMS"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#104B31"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.067" />
<EditText
android:id="@+id/phoneno1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="52dp"
android:ems="10"
app:layout_constraintBottom_toTopOf="@+id/call"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.538" />
<Button
android:id="@+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="184dp"
android:text="options"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.544"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
Pop_up_menu.xml

<?xml version="1.0" encoding="utf-8"?>


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/call"
android:title="Call " />
<item
android:id="@+id/sms"
android:title="Send SMS" />
</menu>

MainActivity.java
package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
EditText edittext1;
Button btncall;
PopupMenu pop1;
RelativeLayout r1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext1 = (EditText) findViewById(R.id.phoneno1);
btncall = (Button) findViewById(R.id.call);
btncall.setOnClickListener(new OnClickListener() {
@SuppressLint("MissingPermission")
@Override
public void onClick(View v) {
PopMenuDisplay1();
} }); }
public void PopMenuDisplay1() {
pop1 = new PopupMenu(MainActivity.this,btncall );
pop1.getMenuInflater().inflate(R.menu.pop_up_menu, pop1.getMenu());
pop1.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@SuppressLint("MissingPermission")
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.call:
String phnumber=edittext1.getText().toString();
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phnumber));
startActivity(callIntent);
return true;
case R.id.sms:
Intent i = new Intent(getBaseContext(), sms.class);
startActivity(i);
return true;
} return true;
} });
pop1.show();
} }
Activity_sms.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=".sms">
<EditText
android:id="@+id/phoneno1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="129dp"
android:layout_marginRight="24dp"
android:ems="10" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/phoneno1"
android:layout_alignLeft="@+id/phoneno1"
android:layout_marginLeft="8dp"
android:layout_marginTop="58dp"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/phoneno1"
android:layout_alignBottom="@+id/phoneno1"
android:layout_toLeftOf="@+id/phoneno1"
android:text="Mobile No:" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignLeft="@+id/textView1"
android:text="Message:" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginLeft="32dp"
android:layout_marginTop="34dp"
android:text="Send SMS" />
<TextView
android:id="@+id/textView4"
android:layout_width="260dp"
android:layout_height="52dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="106dp"
android:layout_marginTop="47dp"
android:layout_marginEnd="44dp"
android:text="SEND SMS"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
Sms.java
package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Bundle;
public class sms extends AppCompatActivity {
EditText mobileno,message;
Button sendsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
mobileno=(EditText)findViewById(R.id.phoneno1);
message=(EditText)findViewById(R.id.editText2);
sendsms=(Button)findViewById(R.id.button1);
mobileno.setText(mobileno.getText());
sendsms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String no=mobileno.getText().toString();
String msg=message.getText().toString();
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);
Toast.makeText(getApplicationContext(), "Message Sent successfully!",
Toast.LENGTH_LONG).show();
} }); }
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phoneservice">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<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=".sms"></activity>
<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>
SMS

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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:id="@+id/textView"
android:layout_width="282dp"
android:layout_height="174dp"
android:text="Android Phone Services - Call And SMS"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#104B31"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.067" />
<EditText
android:id="@+id/phoneno1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="52dp"
android:ems="10"
app:layout_constraintBottom_toTopOf="@+id/call"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.538" />
<Button
android:id="@+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="184dp"
android:text="options"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.544"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
Pop_up_menu.xml

<?xml version="1.0" encoding="utf-8"?>


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/call"
android:title="Call " />
<item
android:id="@+id/sms"
android:title="Send SMS" />
</menu>

MainActivity.java
package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
EditText edittext1;
Button btncall;
PopupMenu pop1;
RelativeLayout r1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edittext1 = (EditText) findViewById(R.id.phoneno1);
btncall = (Button) findViewById(R.id.call);
btncall.setOnClickListener(new OnClickListener() {
@SuppressLint("MissingPermission")
@Override
public void onClick(View v) {
PopMenuDisplay1();
} }); }
public void PopMenuDisplay1() {
pop1 = new PopupMenu(MainActivity.this,btncall );
pop1.getMenuInflater().inflate(R.menu.pop_up_menu, pop1.getMenu());
pop1.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@SuppressLint("MissingPermission")
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.call:
String phnumber=edittext1.getText().toString();
Intent callIntent=new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:"+phnumber));
startActivity(callIntent);
return true;
case R.id.sms:
Intent i = new Intent(getBaseContext(), sms.class);
startActivity(i);
return true;
} return true;
} });
pop1.show();
} }
Activity_sms.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=".sms">
<EditText
android:id="@+id/phoneno1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="129dp"
android:layout_marginRight="24dp"
android:ems="10" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/phoneno1"
android:layout_alignLeft="@+id/phoneno1"
android:layout_marginLeft="8dp"
android:layout_marginTop="58dp"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/phoneno1"
android:layout_alignBottom="@+id/phoneno1"
android:layout_toLeftOf="@+id/phoneno1"
android:text="Mobile No:" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignLeft="@+id/textView1"
android:text="Message:" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginLeft="32dp"
android:layout_marginTop="34dp"
android:text="Send SMS" />
<TextView
android:id="@+id/textView4"
android:layout_width="260dp"
android:layout_height="52dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="106dp"
android:layout_marginTop="47dp"
android:layout_marginEnd="44dp"
android:text="SEND SMS"
android:textAlignment="center"
android:textSize="30sp"
android:textStyle="bold" />
</RelativeLayout>
Sms.java

package com.example.phoneservice;
import androidx.appcompat.app.AppCompatActivity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.os.Bundle;
public class sms extends AppCompatActivity {
EditText mobileno,message;
Button sendsms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
mobileno=(EditText)findViewById(R.id.phoneno1);
message=(EditText)findViewById(R.id.editText2);
sendsms=(Button)findViewById(R.id.button1);
mobileno.setText(mobileno.getText());
sendsms.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String no=mobileno.getText().toString();
String msg=message.getText().toString();
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
PendingIntent pi=PendingIntent.getActivity(getApplicationContext(), 0, intent,0);
SmsManager sms=SmsManager.getDefault();
sms.sendTextMessage(no, null, msg, pi,null);
Toast.makeText(getApplicationContext(), "Message Sent successfully!",
Toast.LENGTH_LONG).show();
} }); }
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.phoneservice">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<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=".sms"></activity>
<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>

You might also like