***************DB HELPER**********************

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

import java.util.ArrayList;

public class DBHelper extends SQLiteOpenHelper {

    private final static String DATABASE_NAME = "UserInfo.db";

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {

        String CREATE_TABLE =
                "CREATE TABLE " + UserProfile.Users.TABLE_NAME + " (" +
                        UserProfile.Users._ID + " INTEGER PRIMARY KEY," +
                        UserProfile.Users.COLUMN_USERNAME + " TEXT," +
                        UserProfile.Users.COLUMN_DOB + " TEXT," +
                        UserProfile.Users.COLUMN_GENDER + " TEXT," +
                        UserProfile.Users.COLUMN_PASSWORD + " TEXT )";

        sqLiteDatabase.execSQL(CREATE_TABLE);
    }

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

    }

    public long addInfo(String username, String password){

        SQLiteDatabase sqLiteDatabase = getWritableDatabase();

        ContentValues contentValues = new ContentValues();
        contentValues.put(UserProfile.Users.COLUMN_USERNAME, username);
        contentValues.put(UserProfile.Users.COLUMN_PASSWORD, password);

        long rowId = sqLiteDatabase.insert(UserProfile.Users.TABLE_NAME, null, contentValues);

        return rowId;
    }

    public int updateInfo(String userId, String userName, String password, String dob, String gender){

        SQLiteDatabase sqLiteDatabase = getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(UserProfile.Users.COLUMN_USERNAME, userName);
        values.put(UserProfile.Users.COLUMN_PASSWORD, password);
        values.put(UserProfile.Users.COLUMN_GENDER, gender);
        values.put(UserProfile.Users.COLUMN_DOB, dob);

        String selection = UserProfile.Users._ID + " = ?";
        String args[] = {userId};

        int count = sqLiteDatabase.update(UserProfile.Users.TABLE_NAME, values, selection, args);

        return count;
    }

    public ArrayList readAllInfo(){

        SQLiteDatabase sqLiteDatabase = getReadableDatabase();

        String[] projection = {

                UserProfile.Users._ID,
                UserProfile.Users.COLUMN_USERNAME,
                UserProfile.Users.COLUMN_DOB,
                UserProfile.Users.COLUMN_GENDER,
                UserProfile.Users.COLUMN_PASSWORD
        };

        String sortOrder = UserProfile.Users._ID + " DESC";

        Cursor cursor = sqLiteDatabase.query(
                UserProfile.Users.TABLE_NAME,
                projection,
                null,
                null,
                null,
                null,
                sortOrder
        );

        ArrayList<User> list = new ArrayList<>();

        if (cursor.getCount() > 0){

            while(cursor.moveToNext()){

                User newUser = new User();

                int id = cursor.getInt(cursor.getColumnIndexOrThrow(UserProfile.Users._ID));
                String user = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_USERNAME));
                String date = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_DOB));
                String gen = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_GENDER));
                String pass = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_PASSWORD));

                newUser.setUserId(id+"");
                newUser.setUserName(user);
                newUser.setDateOfBirth(date);
                newUser.setGender(gen);
                newUser.setPassword(pass);

                list.add(newUser);
            }
        }

        return list;
    }

    public ArrayList readAllInfo(String userId, String userName){

        String selection;
        String[] args = {""};

        if(userId == null){

            selection = UserProfile.Users.COLUMN_USERNAME + " LIKE ?";
            args[0] = userName;
        }
        else
        {
            selection = UserProfile.Users._ID + " = ?";
            args[0] = userId;
        }

        SQLiteDatabase sqLiteDatabase = getReadableDatabase();

        String[] projection = {

                UserProfile.Users._ID,
                UserProfile.Users.COLUMN_USERNAME,
                UserProfile.Users.COLUMN_DOB,
                UserProfile.Users.COLUMN_GENDER,
                UserProfile.Users.COLUMN_PASSWORD
        };



        String sortOrder = UserProfile.Users._ID + " DESC";

        Cursor cursor = sqLiteDatabase.query(
                UserProfile.Users.TABLE_NAME,
                projection,
                selection,
                args,
                null,
                null,
                sortOrder
        );

        ArrayList<User> list = new ArrayList<>();

        if (cursor.getCount() > 0){

            while(cursor.moveToNext()){

                User newUser = new User();

                int id = cursor.getInt(cursor.getColumnIndexOrThrow(UserProfile.Users._ID));
                String user = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_USERNAME));
                String date = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_DOB));
                String gen = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_GENDER));
                String pass = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.Users.COLUMN_PASSWORD));

                newUser.setUserId(id+"");
                newUser.setUserName(user);
                newUser.setDateOfBirth(date);
                newUser.setGender(gen);
                newUser.setPassword(pass);

                list.add(newUser);
            }
        }

        return list;
    }

    public int deleteInfo(String username){

        SQLiteDatabase sqLiteDatabase = getReadableDatabase();

        String selection = UserProfile.Users._ID + " = ?";
        String[] args = {username};

        int deletedRows = sqLiteDatabase.delete(UserProfile.Users.TABLE_NAME, selection, args);

        return deletedRows;
    }
}

*************USER************

public class User {

    private String userId;
    private String userName;
    private String dateOfBirth;
    private String gender;
    private String password;

    public User() {
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

 

********************USER PROFILE**********************

import android.provider.BaseColumns;

public final class UserProfile {

    private UserProfile() {    }

    public static class Users implements BaseColumns {

        public final static String TABLE_NAME = "userInfo";
        public final static String COLUMN_USERNAME = "userName";
        public final static String COLUMN_PASSWORD = "password";
        public final static String COLUMN_GENDER = "gender";
        public final static String COLUMN_DOB = "dateOfBirth";
    }
}

*****************EDIT PROFILE**********************

import android.content.Intent;
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.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.ArrayList;

public class EditProfile extends AppCompatActivity {

    private Button edit,delete,search;
    private EditText uname, dob, pass;
    private RadioGroup radioGroup;
    private RadioButton male, female;
    private String gender;
    private DBHelper dbHelper;
    private String userId;

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

        dbHelper = new DBHelper(this);
        Intent intent = getIntent();
        userId = intent.getStringExtra("id");

        Toast.makeText(EditProfile.this, userId, Toast.LENGTH_SHORT).show();

        uname = findViewById(R.id.userName);
        dob = findViewById(R.id.dateOfB);
        pass = findViewById(R.id.psswrd);
        edit = findViewById(R.id.btnEdit);
        delete = findViewById(R.id.btnDelete);
        search = findViewById(R.id.btnSearch);
        radioGroup = findViewById(R.id.radio);
        male = findViewById(R.id.maleR);
        female = findViewById(R.id.femaleR);

        ArrayList<User> list =  dbHelper.readAllInfo(userId, null);

        if(!list.isEmpty()){

            for (User u : list){

                uname.setText(u.getUserName());
                pass.setText(u.getPassword());
                dob.setText(u.getDateOfBirth());

                if(u.getGender() != null){

                    if(u.getGender().equals("Male")){

                        male.setChecked(true);
                    }
                    else
                    {
                        female.setChecked(true);
                    }
                }
            }
        }

        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int view) {

                if(view == R.id.femaleR){

                    gender = "Female";
                }
                else{

                    gender = "Male";
                }
            }
        });

        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                ArrayList<User> urs = dbHelper.readAllInfo(null, uname.getText().toString());

                for (User u : urs){

                    userId = u.getUserId();
                    uname.setText(u.getUserName());
                    pass.setText(u.getPassword());
                    dob.setText(u.getDateOfBirth());

                    if(u.getGender() != null){

                        if(u.getGender().equals("Male")){

                            male.setChecked(true);
                        }
                        else
                        {
                            female.setChecked(true);
                        }
                    }
                }
            }
        });

        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                String userName = uname.getText().toString();
                String date = dob.getText().toString();
                String pwrd = pass.getText().toString();
                if(female.isChecked()){

                    gender = "Female";
                }
                else{

                    gender = "Male";
                }

                int count = dbHelper.updateInfo(userId, userName, pwrd, date, gender);

                if(count > 0){

                    Toast.makeText(EditProfile.this, "Updated!", Toast.LENGTH_SHORT).show();
                }
                else{

                    Toast.makeText(EditProfile.this, "Something went wrong!", Toast.LENGTH_SHORT).show();
                }
            }
        });

        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                int count = dbHelper.deleteInfo(userId);

                if(count > 0){

                    Toast.makeText(EditProfile.this, "Deleted!", Toast.LENGTH_SHORT).show();
                }
                else{

                    Toast.makeText(EditProfile.this, "Something went wrong!", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}

****************HOME*******************

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.ArrayList;

public class Home extends AppCompatActivity {

    private Button login, reg;
    private EditText uname, pass;
    private DBHelper dbHelper;

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

        dbHelper = new DBHelper(this);

        login = findViewById(R.id.btnLogin);
        reg = findViewById(R.id.btnReg);
        uname = findViewById(R.id.uname);
        pass = findViewById(R.id.pass);

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                ArrayList<User> list = dbHelper.readAllInfo();

                for (User u : list){

                    if(u.getUserName().equals(uname.getText().toString())){
                        if(u.getPassword().equals(pass.getText().toString())){

                            Intent intent = new Intent(Home.this, ProfileManagement.class);
                            intent.putExtra("id", u.getUserId());
                            startActivity(intent);
                        }
                    }
                }
            }
        });

        reg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {

                String user = uname.getText().toString();
                String passwrd = pass.getText().toString();

                dbHelper.addInfo(user, passwrd);

                Toast.makeText(Home.this, "User Registered!", Toast.LENGTH_SHORT).show();
            }
        });
    }
}

****************PROFILE MANAGEMENT*******************

import android.content.Intent;
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.RadioButton;
import android.widget.RadioGroup;

import java.util.ArrayList;

public class ProfileManagement extends AppCompatActivity {

    private Button update;
    private EditText uname, dob, pass;
    private RadioButton male, female;
    private DBHelper dbHelper;
    private String userId;

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

        dbHelper = new DBHelper(this);
        Intent intent = getIntent();
        userId = intent.getStringExtra("id");

        uname = findViewById(R.id.user);
        dob = findViewById(R.id.date);
        pass = findViewById(R.id.word);
        update = findViewById(R.id.btnUpdate);
        male = findViewById(R.id.radioMale);
        female = findViewById(R.id.radioFe);

        ArrayList<User> list =  dbHelper.readAllInfo(userId, null);

        for (User u : list){

            uname.setText(u.getUserName());
            pass.setText(u.getPassword());
            dob.setText(u.getDateOfBirth());

            if(u.getGender() != null){

                if(u.getGender().equals("Male")){

                    male.setChecked(true);
                }
                else
                {
                    female.setChecked(true);
                }
            }
        }

        update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(ProfileManagement.this, EditProfile.class);
                intent.putExtra("id", userId);
                startActivity(intent);
            }
        });
    }
}