Employee Management System Android Application

Employee Management Android Application – In this article I will explain how to develop employee management system android application in Android Studio. Now a days most of major companies and colleges are used Android application for maintain their employee full details like name, address, phone numbers and more. College/Schools also using this management software tool for manage some important documents & information.

It’s secured also when compared to the hand writing documents that’s why most of companies moved in technical way to store their record safely. Current days most of organizations are moved into digital manner for maintain their records. Because it’s very easy to store and retrieve any type of information like employee personal information, salary, address, designation, promotion and more details.

In this project I will add the features of Add, Delete, Edit and Update the employee details. These four operations are enough to manage the perfect Employee Leave Management System. Moreover you can apply this concept in various places such as private institution, Similarly we can get soft copy for anytime when using this software. This is the major reason why everyone should migrate into digital ways.

Create Project – Employee Management System Android

First Create New project, As usual File => New project => Choose Empty Activity or some activity layouts. Here we write only for Adding the records, update the records, edit the records and finally delete the records. That’s very simple back-end process and also attractive graphical interface. Suppose of you are beginner once read official documentation for to learn more about the basic things.

After creating the project open the default file of MainActivity.java class and add the following code. For example purpose here I add this code & then you can get full file from end of article. Because here spaces are not enough to explain everything, so finally give guidelines in zip file.

package in.vetbossel.employeedetails;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    EditText etEmpid,etEmpname;
    Button btnAdd,btnView,btnDelete,btnUpdate;
    TextView tvData;
    DbHandler db;


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


        etEmpid=(EditText)findViewById(R.id.etEmpid);
        etEmpname=(EditText)findViewById(R.id.etEmpname);
        btnAdd=(Button)findViewById(R.id.btnAdd);
        btnUpdate=(Button)findViewById(R.id.btnUpdate);
        btnDelete=(Button)findViewById(R.id.btnDelete);
        btnView=(Button)findViewById(R.id.btnView);
        tvData=(TextView)findViewById(R.id.tvData);
        db=new DbHandler(this);

        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String id=etEmpid.getText().toString();
                String name=etEmpname.getText().toString();
                if(id.length()==0)
                {
                    etEmpid.setError("id is empty");
                    etEmpid.requestFocus();
                    return;
                }
                if(name.length()==0)
                {
                    etEmpname.setError("name is empty");
                    etEmpname.requestFocus();
                    return;
                }
                Employee e=new Employee(Integer.parseInt(id),name);
                db.addEmployee(e);
                etEmpid.setText("");
                etEmpname.setText("");
                etEmpid.requestFocus();


            }
        });
        btnUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String id=etEmpid.getText().toString();
                String name=etEmpname.getText().toString();
                if(id.length()==0)
                {
                    etEmpid.setError("id is empty");
                    etEmpid.requestFocus();
                    return;
                }
                if(name.length()==0)
                {
                    etEmpname.setError("name is empty");
                    etEmpname.requestFocus();
                    return;
                }
                Employee e=new Employee(Integer.parseInt(id),name);
                db.updateEmployee(e);
                etEmpid.setText("");
                etEmpname.setText("");
                etEmpid.requestFocus();

            }
        });
        btnDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String id=etEmpid.getText().toString();
                if(id.length()==0)
                {
                    etEmpid.setError("id is empty");
                    etEmpid.requestFocus();
                    return;
                }

                Employee e=new Employee(Integer.parseInt(id),"");
                db.deleteEmployee(e);
                etEmpid.setText("");
                etEmpid.requestFocus();


            }
        });

        btnView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tvData.setText("");
                ArrayList a=new ArrayList();
                a=db.viewEmployee();
                if(a.size()==0)
                {
                    tvData.setText("no records");
                }
                else
                {
                    for( Employee m: a)
                    {
                        tvData.setText(tvData.getText()+"\n"+m.getId()+":"+m.getName());
                    }
                }
            }
        });

    }
}

Need to initialize the list of Employee names and id’s from SQLite database. Here we use sqlite for storing and retrieve data from database files. When compared to structured database sqlite is much better that’s why most of developers choose sqlite.

Create New java class file and give some name for that to integrate database files. The actual name is DataBase.java, use below code,

package in.vetbossel.employeedetails;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

import java.util.ArrayList;

/**
 * Created by VETRI on 04/04/2019.
 */

public class DbHandler extends SQLiteOpenHelper {
    Context context;
    SQLiteDatabase db;

    DbHandler(Context context)
    {
        super(context,"empdb",null,1);
        this.context=context;
        db=this.getWritableDatabase();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql="create table emp(id integer primary key,name text)";
        db.execSQL(sql);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {

    }

    public void  addEmployee(Employee e)
    {
        ContentValues cv=new ContentValues();
        cv.put("id",e.getId());
        cv.put("name",e.getName());
        long rid=db.insert("emp",null,cv);
        if(rid<0)
            Toast.makeText(context, "insert issue", Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(context, "1 record inserted", Toast.LENGTH_SHORT).show();

    }

    public void updateEmployee(Employee e)
    {
        ContentValues cv=new ContentValues();
        cv.put("id",e.getId());
        cv.put("name",e.getName());
        long nor=db.update("emp",cv,"id="+e.getId(),null); //number of records
        Toast.makeText(context, nor+"records updated", Toast.LENGTH_SHORT).show();

    }

    public void deleteEmployee(Employee e)
    {
        long nor=db.delete("emp","id="+e.getId(),null);
        Toast.makeText(context, nor+"records deleted", Toast.LENGTH_SHORT).show();

    }

    public ArrayList viewEmployee()
    {
        Cursor c=db.query("emp",null,null,null,null,null,null);
        c.moveToFirst();
        ArrayList a=new ArrayList<>();

        if(c.getCount()>0)
        {
            do {
                String id=c.getString(0);
                String name=c.getString(1);
                Employee b=new Employee(Integer.parseInt(id),name);
                a.add(b);

            }while (c.moveToNext());

        }
        return a;

    }
}

Activity Layouts

Now time to integrate java files with XML layouts to make better interface for users. But in this project I will did not make attractive interface just develop the concept only with actual interface designs.

Just open the default XML file of activity_main.xml file and add the following code below

Screenshot – Employee Management System Android

Download Source Code

Click to get the full source code of Employee Management System Android Application. I hope this project helps you to build perfect project in your Android Studio IDE. If you are facing any issues just comment below I will help to resolve your issues.

Leave a Reply