Javascript required

Semester VI


Bsc.Physical Science Computer Science (CBCS) Programs


Android Programs



Question 1 : Create "Hello World" application. That will display “Hello World” in the middle of the
             screen in the emulator. Also display “Hello World” in the middle of the screen in the
             Android Phone.
                                
 JAVA Code
                                    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 Code
                                    <?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.intro_page.MainActivity">

    <TextView
        android:text="HELLO WORLD"
        android:textColor="@color/colorPrimary1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/textView" />
</RelativeLayout>
                                

Question 2 : Create an application with login module. (Check username and password).
                                
 JAVA Code
                                    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;

import static android.widget.Toast.LENGTH_LONG;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void login(View view) {
        String s1="Authorised User";
        String s2="Non Authorised User";
        EditText e1 = (EditText) findViewById(R.id.editText);
        EditText e2 = (EditText) findViewById(R.id.editText2);
        TextView t=(TextView) findViewById(R.id.t1);
        if (e1.getText().toString().equals("Admin") && e2.getText().toString().equals("123")) {
            t.setText(s1);
        } else {
           t.setText(s2);
        }

    }
}
                                
XML Code
                                    <?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.loginauth.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/colorPrimary1"
        android:textSize="2.5mm"
        android:id="@+id/user"
        android:layout_alignParentStart="true" />

    <TextView
        android:text="Password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pass"
        android:textSize="2.5mm"
        android:textColor="@color/colorPrimary1"
        android:layout_marginTop="49dp"
        android:layout_below="@+id/editText"
        android:layout_alignEnd="@+id/user" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text=""
        android:ems="10"
        android:id="@+id/editText"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/editText2"
        android:layout_marginStart="11dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/editText2"
        android:layout_alignTop="@+id/pass"
        android:layout_toEndOf="@+id/button" />

    <Button
        android:text="login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:onClick="login"
        android:layout_marginTop="55dp"
        android:layout_marginStart="49dp"
        android:layout_below="@+id/editText2"
        android:layout_alignStart="@+id/pass" />

    <TextView
        android:text="Waiting..."
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button"
        android:layout_toEndOf="@+id/button"
        android:layout_marginTop="42dp"
        android:id="@+id/t1" />
</RelativeLayout>
                                

Question 3 : Create spinner with strings taken from resource folder (res >> value folder) and on
             changing the spinner value, Image will change.
                                
 JAVA Code
                                    /* NOTE: 1. Download any three images and then named them beer, flower and fruit respectively.
         2. Now, put them in a folder named Drawable if already there (res >> Drawable) if not 
            then create it. Follow these steps :
               1. Go to the folder where your project is saved.
               2. Go to the resource directory named as res, now create a directory named as Drawable
               3. Copy the images.*/
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Spinner;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void flowers(View view) {
        Spinner s = (Spinner) findViewById(R.id.s);
        String g = String.valueOf(s.getSelectedItem());
        ImageView q = (ImageView) findViewById(R.id.pc);

        switch (g)
        {
            case "Beer":
                q.setImageResource(R.drawable.beer);
                break;

            case "Flower":
                q.setImageResource(R.drawable.flower);
                break;
            case "Fruits":
                q.setImageResource(R.drawable.fruit);
                break;
        }
    }
}
                                
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/activity_bingo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.intro_page.MainActivity">

    <Spinner
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/s"
        android:entries="@array/spin"
        android:layout_below="@+id/textView2"
        android:layout_toEndOf="@+id/textView2"
        android:layout_marginTop="55dp" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@mipmap/ic_launcher"
        android:id="@+id/pc"
        android:layout_below="@+id/button"
        android:layout_toEndOf="@+id/textView2"
        android:layout_marginStart="99dp"
        android:layout_marginTop="101dp" />

    <Button
        android:text="Select"
        android:onClick="flowers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_marginTop="60dp"
        android:layout_alignTop="@+id/s"
        android:layout_alignStart="@+id/pc" />
</RelativeLayout>
                                
STRING XML
                                    <resources>
    <string name="app_name">Spinner</string>
    <string-array name="spin">
        <item>Beer</item>
        <item>Flower</item>
        <item>Fruits</item>
    </string-array>
</resources>
                                

Question 4 : Create a menu with 5 options and and selected option should appear in text box.
                                
 JAVA Code
                                    import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inf=getMenuInflater();
        inf.inflate(R.menu.menu, menu);
        return true;

    }
    public boolean onOptionsItemSelected(MenuItem item)
    {
        TextView t=(TextView)findViewById(R.id.textView2);
        switch(item.getItemId())
        {
            case R.id.cars:
                t.setText("Cars selected");
                break;

            case R.id.train:
                t.setText("Train selected");
                break;

            default:
                t.setText("dont select it");
        }
        return true;
    }
}
                                
XML Code
                                    <?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:id="@+id/activity_govo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.intro_page.MainActivity">

    <TextView
        android:text="TextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="45dp"
        android:layout_marginTop="155dp"
        android:id="@+id/textView2" />
</RelativeLayout>
                                
MENU XML
                                    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/cars"
        android:title="CARS"/>

    <item android:id="@+id/train"
        android:title="TRAIN"/>
</menu>
                                

Question 5 : Create a list of all courses in your college and on selecting a particular course teacher-incharge
             of that course should appear at the bottom of the screen.
                                
 JAVA Code
                                    import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    String s1 = "Diksha Ma'am";
    String s2 = "Harinder Singh Sir";
    String s3 = "Ravi Kumar Sir";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView((int) R.layout.activity_main);
    }

    public void Select(View view) {
        boolean checked = ((RadioButton) view).isChecked();
        switch (view.getId()) {
            case R.id.radioButton:
                if (checked) {
                    Toast.makeText(getApplicationContext(), this.s1,Toast.LENGTH_SHORT).show();
                    return;
                }
                return;
            case R.id.radioButton2:
                if (checked) {
                    Toast.makeText(getApplicationContext(), this.s2,Toast.LENGTH_SHORT).show();
                    return;
                }
                return;
            case R.id.radioButton3:
                if (checked) {
                    Toast.makeText(getApplicationContext(), this.s3,Toast.LENGTH_SHORT).show();
                    return;
                }
                return;
            default:
                Toast.makeText(getApplicationContext(), "Wrong Choice ..!!",Toast.LENGTH_SHORT).show();
                return;
        }
    }
}
                                
XML Code
                                    <?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">
    <RadioGroup android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TextView android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="Teachers Name"
            android:textColor="@color/colorPrimary1"
            android:textSize="3mm"
            android:layout_alignParentTop="true"
            android:layout_marginStart="19dp"
            android:layout_alignParentStart="true" />
        <RadioButton android:id="@+id/radioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="Computer"
            android:onClick="Select" />
        <RadioButton android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:text="Maths"
            android:layout_below="@+id/radioButton"
            android:onClick="Select"
            android:layout_alignStart="@+id/radioButton" />
        <RadioButton android:id="@+id/radioButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:text="Physics"
            android:layout_below="@+id/radioButton2"
            android:onClick="Select"
            android:layout_alignStart="@+id/radioButton2" />
    </RadioGroup>
</RelativeLayout>
                                

Question 6 : Create an application with three option buttons, on selecting a button colour of the screen
             will change.
                                
 JAVA Code
                                    import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;


public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void select(View view)
    {
        Button a=(Button)findViewById(R.id.b1);
        RelativeLayout L1=(RelativeLayout)findViewById(R.id.activity_main);
        L1.setBackgroundColor(Color.RED);
    }
    public void select1(View view)
    {
        Button b=(Button)findViewById(R.id.b2);
        RelativeLayout L1=(RelativeLayout)findViewById(R.id.activity_main);

        L1.setBackgroundColor(Color.BLUE);}


    public void select2(View view)
    {
        Button b=(Button)findViewById(R.id.b3);
        RelativeLayout L1=(RelativeLayout)findViewById(R.id.activity_main);
        L1.setBackgroundColor(Color.BLACK);
    }
}
                                
XML Code
                                    <?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.intro_page.MainActivity">
    <Button
        android:text="RED"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:layout_alignParentStart="true"
        android:layout_marginStart="60dp"
        android:layout_marginTop="85dp"
        android:id="@+id/b1"
        android:onClick="select"/>
    <Button
        android:text="BLUE"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/b1"
        android:layout_alignEnd="@+id/b1"
        android:layout_marginTop="27dp"
        android:id="@+id/b2"
        android:onClick="select1"/>

    <Button
        android:text="BLACK"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="42dp"
        android:id="@+id/b3"
        android:layout_below="@+id/b2"
        android:layout_alignStart="@+id/b2"
        android:onClick="select2"/>
</RelativeLayout>
                                

Question 7 : Create and Login application as above. On successful login, pop up the message.
                                
 JAVA Code
                                    import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import static android.widget.Toast.LENGTH_LONG;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void login(View view) {
        EditText e1 = (EditText) findViewById(R.id.editText);
        EditText e2 = (EditText) findViewById(R.id.editText2);
        if (e1.getText().toString().equals("Admin") && e2.getText().toString().equals("123")) {
            Toast.makeText(getApplicationContext(), "Authrised user", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), " Not Authrised user", LENGTH_LONG).show();
        }

    }
}
                                
XML Code
                                    <?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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.hp.loginauth.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:id="@+id/user"
        android:layout_alignParentStart="true" />

    <TextView
        android:text="Password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pass"
        android:layout_marginTop="49dp"
        android:layout_below="@+id/editText"
        android:layout_alignEnd="@+id/user" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text=""
        android:ems="10"
        android:id="@+id/editText"
        android:layout_alignParentTop="true"
        android:layout_alignStart="@+id/editText2"
        android:layout_marginStart="11dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPassword"
        android:ems="10"
        android:id="@+id/editText2"
        android:layout_alignTop="@+id/pass"
        android:layout_toEndOf="@+id/button" />

    <Button
        android:text="login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:onClick="login"
        android:layout_marginTop="55dp"
        android:layout_marginStart="49dp"
        android:layout_below="@+id/editText2"
        android:layout_alignStart="@+id/pass" />
</RelativeLayout>
                                

Question 8 : Create an application to Create, Insert, update, Delete and retrieve operation on the
             database.
                                
 JAVA Code
                                       DbAdapter.java
                                import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DbAdapter {

    //define static variable
    public static int dbversion =6;
    public static String dbname = "ContactsDB";
    public static String dbTable = "contacts";

    private static class DatabaseHelper extends SQLiteOpenHelper {
        public DatabaseHelper(Context context) {
            super(context,dbname,null, dbversion);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("CREATE TABLE IF NOT EXISTS "+dbTable+" 
            (_id INTEGER PRIMARY KEY autoincrement,name, number, email, address, UNIQUE(number))");
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS "+dbTable);
            onCreate(db);
        }
    }

    //establsh connection with SQLiteDataBase
    private final Context c;
    private DatabaseHelper dbHelper;
    private SQLiteDatabase sqlDb;

    public DbAdapter(Context context) {
        this.c = context;
    }
    public DbAdapter open() throws SQLException {
        dbHelper = new DatabaseHelper(c);
        sqlDb = dbHelper.getWritableDatabase();
        return this;
    }

    //insert data
    public void insert(String text2,String text3,String text4,String text5) {
        if(!isExist(text3)) {
            sqlDb.execSQL("INSERT INTO contacts (name,number,email,address) 
            VALUES('" + text2 + "','" + text3 + "','" + text4 + "','" + text5 + "')");
        }
    }
    //check entry already in database or not
    public boolean isExist(String num){
        String query = "SELECT number FROM contacts WHERE number='"+num+"' LIMIT 1";
        Cursor row = sqlDb.rawQuery(query, null);
        return row.moveToFirst();
    }
    //edit data
    public void update(int id,String text2,String text3,String text4,String text5) {
        sqlDb.execSQL("UPDATE "+dbTable+" SET name='"+text2+"', number='"+text3+"',
        email='"+text4+"', address='"+text5+"'   WHERE _id=" + id);
    }

    //delete data
    public void delete(int id) {
        sqlDb.execSQL("DELETE FROM "+dbTable+" WHERE _id="+id);
    }

    //fetch data
    public Cursor fetchAllData() {
        String query = "SELECT * FROM "+dbTable;
        Cursor row = sqlDb.rawQuery(query, null);
        if (row != null) {
            row.moveToFirst();
        }
        return row;
    }

    //fetch data by filter
    public Cursor fetchdatabyfilter(String inputText,String filtercolumn) throws SQLException {
        Cursor row = null;
        String query = "SELECT * FROM "+dbTable;
        if (inputText == null  ||  inputText.length () == 0)  {
            row = sqlDb.rawQuery(query, null);
        }else {
            query = "SELECT * FROM "+dbTable+" WHERE "+filtercolumn+" like '%"+inputText+"%'";
            row = sqlDb.rawQuery(query, null);
        }
        if (row != null) {
            row.moveToFirst();
        }
        return row;
    }
}
                                
                                        DetailsContact.java
                                import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class DetailsContact extends AppCompatActivity {
    DbAdapter db;
    String id,name,number,email,address;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.details_contact);

        Intent intent = getIntent();
        id = intent.getStringExtra("ID");
        name = intent.getStringExtra("NAME");
        number = intent.getStringExtra("NUMBER");
        email = intent.getStringExtra("EMAIL");
        address = intent.getStringExtra("ADDRESS");
        ((TextView) findViewById(R.id.name)).setText(name);
        ((TextView) findViewById(R.id.number)).setText(number);
        ((TextView) findViewById(R.id.email)).setText(email);
        ((TextView) findViewById(R.id.address)).setText(address);
        //calling DbAdapter
        db = new DbAdapter(this);
        db.open();
    }
    public void Edit(View v){
        //go to EditContact page
        Intent edit = new Intent(DetailsContact.this, EditContact.class);
        edit.putExtra("ID", id);
        edit.putExtra("NAME", name);
        edit.putExtra("NUMBER", number);
        edit.putExtra("EMAIL", email);
        edit.putExtra("ADDRESS",address);
        startActivity(edit);
    }
    public void Delete(View v){
        db.delete(Integer.parseInt(id));
        Toast.makeText(getApplicationContext(),"deleted", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onBackPressed() {
        finish();
        Intent i = new Intent(this, MainActivity.class);
        startActivity(i);
    }
} 
                                
                                    EditContact.java
                                    import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class EditContact extends AppCompatActivity {
    DbAdapter db;
    String id,name,number,email,address;
    EditText etname,etnumber,etemail,etaddress;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_contact);

        Intent intent = getIntent();
        id = intent.getStringExtra("ID");
        name = intent.getStringExtra("NAME");
        number = intent.getStringExtra("NUMBER");
        email = intent.getStringExtra("EMAIL");
        address = intent.getStringExtra("ADDRESS");
        ((EditText) findViewById(R.id.name)).setText(name);
        ((EditText) findViewById(R.id.number)).setText(number);
        ((EditText) findViewById(R.id.email)).setText(email);
        ((EditText) findViewById(R.id.address)).setText(address);
        //calling DbAdapter
        db = new DbAdapter(this);
        db.open();
        //get data from text feld
        etname =(EditText)findViewById(R.id.name);
        etnumber =(EditText)findViewById(R.id.number);
        etemail =(EditText)findViewById(R.id.email);
        etaddress = (EditText)findViewById(R.id.address);
    }
    public void Save(View v){
        name=etname.getText().toString();
        number=etnumber.getText().toString();
        email=etemail.getText().toString();
        address=etaddress.getText().toString();
        db.update(Integer.parseInt(id),name, number, email, address);
        Toast.makeText(getApplicationContext(),"Update success", Toast.LENGTH_SHORT).show();
    }
    @Override
    public void onBackPressed() {
        finish();
        Intent i = new Intent(this, MainActivity.class);
        startActivity(i);
    }
} 
                                
                                    addNewContact.java
                                    import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;

public class addNewContact extends AppCompatActivity {
    //calling variables
    DbAdapter db;
    EditText etname,etnumber,etemail,etaddress;
    String name,number,email,address;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_contact);
        //get data from text feld
        etname =(EditText)findViewById(R.id.name);
        etnumber =(EditText)findViewById(R.id.number);
        etemail =(EditText)findViewById(R.id.email);
        etaddress = (EditText)findViewById(R.id.address);
        //calling DbAdapter
        db = new DbAdapter(this);
        db.open();
    }
    public void Save(View v){
        if(db.isExist(number)){
            Toast.makeText(getApplicationContext(),"already exist", Toast.LENGTH_SHORT).show();
        }else{
            name=etname.getText().toString();
            number=etnumber.getText().toString();
            email=etemail.getText().toString();
            address=etaddress.getText().toString();
            db.insert(name,number,email,address);
            Toast.makeText(getApplicationContext(),"Contact added", Toast.LENGTH_SHORT).show();
        }

    }
    @Override
    public void onBackPressed() {
        finish();
        Intent i = new Intent(this, MainActivity.class);
        startActivity(i);
    }
}
                                
                                    MainActivity.java
                                import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {

    //calling variables
    DbAdapter db;
    SimpleCursorAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //calling DbAdapter
        db = new DbAdapter(this);
        db.open();
        //initially insert some data
        //db.insert("Color Picker", "+840885654", "info@icyarena.com", "US");
        //db.insert("Mike Helen", "+808853437", "halen@icyarena.com", "UK");
        //db.insert("Robart Pink", "+808851234", "robart@icyarena.com", "AUS");
        //display data
        ListView lv = (ListView) findViewById(R.id.listView1);
        int layoutstyle=R.layout.liststyle;
        int[] xml_id = new int[] {
                R.id.txtname,
                R.id.txtnumber
        };
        String[] column = new String[] {
                "name",
                "number"
        };
        Cursor row = db.fetchAllData();
        adapter = new SimpleCursorAdapter(this, layoutstyle,row,column, xml_id, 0);
        lv.setAdapter(adapter);
        //onClick function
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView adapterview, View view, int position, long id) {
                Cursor row = (Cursor) adapterview.getItemAtPosition(position);
                String _id = row.getString(row.getColumnIndexOrThrow("_id"));
                String name = row.getString(row.getColumnIndexOrThrow("name"));
                String number = row.getString(row.getColumnIndexOrThrow("number"));
                String email = row.getString(row.getColumnIndexOrThrow("email"));
                String address = row.getString(row.getColumnIndexOrThrow("address"));
                //go to detailsContact page
                Intent todetais = new Intent(MainActivity.this, DetailsContact.class);
                todetais.putExtra("ID",_id);
                todetais.putExtra("NAME", name);
                todetais.putExtra("NUMBER",number);
                todetais.putExtra("EMAIL",email);
                todetais.putExtra("ADDRESS",address);
                startActivity(todetais);
            }
        });
        //dispay data by filter
        EditText et = (EditText) findViewById(R.id.myFilter);
        et.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable s) {
            }
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                adapter.getFilter().filter(s.toString());
            }
        });
        adapter.setFilterQueryProvider(new FilterQueryProvider() {
            public Cursor runQuery(CharSequence constraint) {
                return db.fetchdatabyfilter(constraint.toString(),"name");
            }
        });
    }
    public void addContact(View v){
        Intent addNewContact = new Intent(MainActivity.this, addNewContact.class);
        startActivity(addNewContact);


    }

}
                                
XML Code
                                      AndroidManifest.xml
                                    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.contactlist" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        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>
        <activity
            android:name=".addNewContact"
            android:label="Add new contact" />
        <activity
            android:name=".DetailsContact"
            android:label="Contact Details" />
        <activity
            android:name=".EditContact"
            android:label="Edit Contact" />
    </application>

</manifest>
                                
                                    actvity_main.xml
                                    <?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">
    <EditText android:id="@+id/myFilter" android:layout_width="match_parent"
        android:layout_height="wrap_content" android:ems="10"
        android:hint="Search.....">
    </EditText>
    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/listView1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_above="@+id/add"
        android:layout_below="@+id/myFilter" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Add"
        android:id="@+id/add"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="addContact" />
</RelativeLayout>
                                
                                    details_contact.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">
    <LinearLayout
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Name"
            android:ems="10"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:ems="10"
            android:id="@+id/name"
            android:layout_gravity="center_horizontal" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Number"
            android:ems="10"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="phone"
            android:ems="10"
            android:id="@+id/number"
            android:layout_gravity="center_horizontal" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Email"
            android:ems="10"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"
            android:ems="10"
            android:id="@+id/email"
            android:layout_gravity="center_horizontal" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:text="Address"
            android:ems="10"
            android:layout_gravity="center_horizontal" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:ems="10"
            android:id="@+id/address"
            android:layout_gravity="center_horizontal" />


    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Edit"
        android:onClick="Edit"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Delete"
        android:onClick="Delete"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>
                                
                                    liststyle.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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/txtname" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:layout_marginBottom="10dip"
        android:id="@+id/txtnumber" />

</LinearLayout>
                                
                                    store_contact.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">
    <LinearLayout
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPersonName"
            android:hint="Name"
            android:ems="10"
            android:id="@+id/name"
            android:layout_gravity="center_horizontal" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="phone"
            android:hint="Number"
            android:ems="10"
            android:id="@+id/number"
            android:layout_gravity="center_horizontal" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"
            android:hint="Email"
            android:ems="10"
            android:id="@+id/email"
            android:layout_gravity="center_horizontal" />

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textMultiLine"
            android:ems="10"
            android:id="@+id/address"
            android:layout_gravity="center_horizontal"
            android:hint="Address" />


    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Save"
        android:id="@+id/save"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="Save" />

</RelativeLayout>