этот код работает для обновления удалить поиск андроид студии Apweslk - PullRequest
0 голосов
/ 14 октября 2018

создание базы данных и других вещей в классе dbhelper

public class DBHandler extends SQLiteOpenHelper{
private static final String TAG =DBHandler.class.getSimpleName();
private static final int VERSION =1;
private static final String DATABASE_NAME = "userDb.db";



private String CREATE_TABLE ="CREATE TABLE " + Users.TABLE_NAME + "("
        + Users._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + Users.USER_NAME + " TEXT,"
        + Users.USER_DOB + " TEXT," + Users.USER_GENDER + " TEXT," + Users.USER_PASSWORD + " TEXT " + ")";

private String DROP_TABLE ="DROP TABLE IF EXISTS " +Users.TABLE_NAME;
public DBHandler(Context context) {
    super(context, DATABASE_NAME, null, VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(DROP_TABLE);
    onCreate(db);
}

вставка данных в базу данных sqlite

//adding users
public boolean addInfo(Users addUser){
    boolean result = true;
    try {
        SQLiteDatabase db =this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(Users.USER_NAME,addUser.getUserName());
        values.put(Users.USER_DOB,addUser.getDob());
        values.put(Users.USER_GENDER,addUser.getGender());
        values.put(Users.USER_PASSWORD,addUser.getPassword());
        result =db.insert(Users.TABLE_NAME,null,values)>0;
    }
    catch (Exception ex){
        result=false;
        ex.getMessage();
    }
    return result;
}

метод обновления базы данных. Это возможно сделать

//updateInfor()
public boolean updateInfor(Users updateUser){
    boolean result = true;
    try{
        SQLiteDatabase db =this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(Users.USER_NAME,updateUser.getUserName());
        values.put(Users.USER_DOB,updateUser.getDob());
        values.put(Users.USER_GENDER,updateUser.getGender());
        values.put(Users.USER_PASSWORD,updateUser.getPassword());
        //update using user id
        String[] hello ={String.valueOf(updateUser.getUserName())};
        result =db.update(Users.TABLE_NAME,values,Users.USER_NAME+ "=? ",hello) >0;
    }
    catch (Exception ex){
        result =false;
    }
    return result;
}

извлечение всех данных из базы данных`

//retrieve data from database
public List<Users>readAllInfor(){
    String[] columns ={Users.USER_NAME,Users.USER_DOB,Users.USER_GENDER,Users.USER_PASSWORD};
    List<Users> usersList = new ArrayList<Users>();
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(Users.TABLE_NAME,columns,null,null,null,null,null);
    if(cursor.moveToFirst()){
        do{
            Users user = new Users();
            user.setUserId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(Users._ID))));
            user.setUserName(cursor.getString(cursor.getColumnIndex(Users.USER_NAME)));
            user.setDob(cursor.getString(cursor.getColumnIndex(Users.USER_DOB)));
            user.setGender(cursor.getString(cursor.getColumnIndex(Users.USER_GENDER)));
            user.setPassword(cursor.getString(cursor.getColumnIndex(Users.USER_PASSWORD)));

            usersList.add(user);
        }while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return usersList;
}

извлечение данных из базы данных с использованием собственного идентификатора

//overloading method to retrive by id
public Cursor readAllInfor(String user){
    SQLiteDatabase db = getReadableDatabase();

    Cursor cursor = db.rawQuery("SELECT * FROM "+UserProfile.Users.table_name+" WHERE "+UserProfile.Users.Column_UserName+" = '"+user+"'",null);

    return  cursor;
 }

удаление пользователя из базы данных

public boolean deleteUser(Users user){
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(Users.TABLE_NAME,Users._ID + "=?",
            new String[]{String.valueOf(user.getUserId())});
    db.close();
    return true;
}

часть входапроверка пользователя с использованием имени пользователя и пароля

 public Users checkUser(String email,String password){
    Users users =null;
    try {
        SQLiteDatabase db = getReadableDatabase();
        Cursor cursor = db.rawQuery("SELECT * FROM " + Users.TABLE_NAME + " WHERE userName = ? AND userPassword = ?" ,new String[]{email,password} );
        if (cursor.moveToFirst()){
            users = new Users();
            users.setUserId(cursor.getInt(0));
            users.setUserName(cursor.getString(1));
            users.setDob(cursor.getString(2));
            users.setGender(cursor.getString(3));
            users.setPassword(cursor.getString(4));
        }
    }catch (Exception e){
        users=null;
    }
    return users;

}

импликация всех методов в db helper

public class ProfileManangment extends AppCompatActivity implements View.OnClickListener{
private final AppCompatActivity activity = ProfileManangment.this;
private RadioGroup groupGender;
private RadioButton radioButton;
private EditText username,password,dob;
private Button update;
private Users users;
private DBHandler dbHandler;



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

    iniViews();
    iniObjects();
    iniListners();
}

private void iniViews() {
    username =findViewById(R.id.regUsername);
    password =findViewById(R.id.regPassword);
    dob =findViewById(R.id.regDob);
    update=findViewById(R.id.btnUpadateReg);
    groupGender = findViewById(R.id.radioGroupGender);
}

private void iniObjects() {
    users =new Users();
    dbHandler =new DBHandler(activity);
}

private void iniListners() {
    update.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.btnUpadateReg : addtoDataBase();
        break;

    }

}

//get values of readio button
public void radioButtonValue(View v){
    int radioId = groupGender.getCheckedRadioButtonId();
    radioButton =findViewById(radioId);
}

private void addtoDataBase() {
    users.setUserName(username.getText().toString().trim());
    users.setDob(dob.getText().toString().trim());

    int radioId = groupGender.getCheckedRadioButtonId();
    radioButton =findViewById(radioId);

    users.setGender(radioButton.getText().toString().trim());
    users.setPassword(password.getText().toString().trim());
    boolean result =dbHandler.addInfo(users);
    if(result){
        Toast.makeText(ProfileManangment.this,"SUCCESSFULLY REGISTERED",Toast.LENGTH_LONG).show();
        Intent intentEditProfile = new Intent(ProfileManangment.this,EditProfile.class);
        startActivity(intentEditProfile);
    }
    else
        Toast.makeText(ProfileManangment.this,"AN ERROR OCCURRED",Toast.LENGTH_LONG).show();
}

}

поиск - это самое важное. Скажите, пожалуйста, любойОсновная информация о том, как использовать поиск .Мой код выглядит следующим образом:

/**
 * StringBuffer was used in aid of using the AlertDialog.Builder to display all the stuff
 * on the screen
 */
public void search(View view) {
    User user = db.readAllInfor(ET_username.getText().toString());

    if(user == null) {
        showStuff("Error", "No Data Found!");
        return;
    }

    StringBuffer buffer = new StringBuffer();
    buffer.append("User ID: " + user.getId() + "\n");
    buffer.append("Username: " + user.getUsername() + "\n");
    buffer.append("Date Of Birth: " + user.getDateOfBirth() + "\n");
    buffer.append("Password: " + user.getPassword() + "\n");
    buffer.append("Gender: " + user.getGender() + "\n\n");

    showStuff("Data", buffer.toString());
}

/**
 * This was done in the aid of displaying the stuff on the screen
 */
public void showStuff(String title, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.show();
}

пользовательский класс, который создает методы получения и установки и столбцы таблицы

class Users implements BaseColumns{
public static final String TABLE_NAME = "user";
public static final String USER_NAME = "userName";
public static final String USER_PASSWORD = "userPassword";
public static final String USER_DOB = "dob";
public static final String USER_GENDER = "userGender";

private int userId;
private String userName;
private String Password;
private String dob;
private String gender;

public Users(){}

Ответы [ 2 ]

0 голосов
/ 15 октября 2018

// Профиль пользователя

public final class UserProfile {
private UserProfile(){}

public static class UserPro implements BaseColumns{
    public static final String TABLE_NAME = "UserInfo";
    public static final String COLUMN_NAME_USERNAME = "userName";
    public static final String COLUMN_NAME_DOB = "dateOfBirth";
    public static final String COLUMN_NAME_GENDER = "Gender";
}

}

// DBHelper

public class DBHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "UserInfo.db";



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

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase){
    String SQL_CREATE_ENTRIES =
            "CREATE TABLE " + UserProfile.UserPro.TABLE_NAME + " (" +
                    UserProfile.UserPro._ID + " INTEGER PRIMARY KEY," +
                    UserProfile.UserPro.COLUMN_NAME_USERNAME + " TEXT," +
                    UserProfile.UserPro.COLUMN_NAME_DOB + " TEXT," +
                    UserProfile.UserPro.COLUMN_NAME_GENDER + " TEXT)";

    sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES);
}

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

}

public void addInfo(String username, String password){
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(UserProfile.UserPro.COLUMN_NAME_USERNAME, username);

    sqLiteDatabase.insert(UserProfile.UserPro.TABLE_NAME, null, values);
}

public Boolean updateInfo(String username, String newpassword, String newdob, String newgender){
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(UserProfile.UserPro.COLUMN_NAME_USERNAME, username);
    values.put(UserProfile.UserPro.COLUMN_NAME_GENDER, newgender);
    values.put(UserProfile.UserPro.COLUMN_NAME_DOB, newdob);

    String selection = UserProfile.UserPro.COLUMN_NAME_USERNAME + " LIKE ?";
    String[] selectionArgs = {username};

    int count = sqLiteDatabase.update(
            UserProfile.UserPro.TABLE_NAME,
            values,
            selection,
            selectionArgs
    );

    if(count>=1)
        return true;
    else
        return false;
}

public List readAllInfo(){
    SQLiteDatabase sqLiteDatabase = getReadableDatabase();

    String[] projection = {
            BaseColumns._ID,
            UserProfile.UserPro.COLUMN_NAME_USERNAME,
            UserProfile.UserPro.COLUMN_NAME_DOB,
            UserProfile.UserPro.COLUMN_NAME_GENDER
    };

    String sortOrder = UserProfile.UserPro.COLUMN_NAME_USERNAME + " ASC";

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

    List users = new ArrayList<>();
    List dobs = new ArrayList<>();
    List genders = new ArrayList<>();

    while (cursor.moveToNext()){
        String username = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.UserPro.COLUMN_NAME_USERNAME));
        String dob = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.UserPro.COLUMN_NAME_DOB));
        String gender = cursor.getString(cursor.getColumnIndexOrThrow(UserProfile.UserPro.COLUMN_NAME_GENDER));

        users.add(username);
        dobs.add(dob);
        genders.add(gender);
    }

    cursor.close();

    return  users;
} 

public Cursor readAllInfo(String username){
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();
    String selection = UserProfile.UserPro.COLUMN_NAME_USERNAME + " = ?";
    String[] selectionArgs = {username};

    Cursor data = sqLiteDatabase.rawQuery("SELECT * FROM " + UserProfile.UserPro.TABLE_NAME + " WHERE " + UserProfile.UserPro.COLUMN_NAME_USERNAME + " = ?", selectionArgs);
    return data;
}

public int deleteInfo(String username){
    SQLiteDatabase sqLiteDatabase = getWritableDatabase();

    String selection = UserProfile.UserPro.COLUMN_NAME_USERNAME + " LIKE ?";
    String[] selectionArgs = {username};

    int deletedRows = sqLiteDatabase.delete(UserProfile.UserPro.TABLE_NAME, selection, selectionArgs);

    return deletedRows;
}

}

// Домашняя деятельность

public class HomeActivity extends AppCompatActivity {
private final AppCompatActivity activity = HomeActivity.this;

private EditText userName;
private EditText password;
private RadioButton genderMale;
private RadioButton genderFemale;

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

    userName = findViewById(R.id.UserNameEditText);
    password = findViewById(R.id.PasswordEditText);
}

public void onClickRegister(View view){

    DBHelper dbHelper = new DBHelper(activity);

    dbHelper.addInfo(userName.getText().toString().trim(), password.getText().toString().trim());

    Toast.makeText(HomeActivity.this, "User Added", Toast.LENGTH_LONG).show();

    Intent intent = new Intent(HomeActivity.this, ProfileManagementActivity.class);
    startActivity(intent);
}

}

// Редактировать профиль

public class EditProfileActivity extends AppCompatActivity {
private final AppCompatActivity activity = EditProfileActivity.this;

private Button deleteButton;
private EditText userName;
private EditText password;
private EditText dob;
private RadioButton genderMale;
private RadioButton genderFemale;
private String gender;

private DBHelper dbHelper;

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

    deleteButton = findViewById(R.id.DeleteButton);
    userName = findViewById(R.id.UserNameEditText);
    password = findViewById(R.id.PasswordEditText);
    dob = findViewById(R.id.DOBEditText);
    genderMale = findViewById(R.id.MaleRadioButton);
    genderFemale = findViewById(R.id.FemaleRadioButton);

    genderMale.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onRadioButtonClicked(genderMale);
        }
    });

    genderFemale.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onRadioButtonClicked(genderFemale);
        }
    });

    deleteButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int rows = dbHelper.deleteInfo(userName.getText().toString().trim());

            if(rows>0)
                Toast.makeText(EditProfileActivity.this, "Entry Deleted", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(EditProfileActivity.this, "Delete Failed", Toast.LENGTH_LONG).show();
        }
    });



    dbHelper = new DBHelper(activity);

}

public void ReadAllInfo(View view){

    Cursor data = dbHelper.readAllInfo(userName.getText().toString());

    if(data.getCount() == 0){
        showMessage("Error", "Nothing found");
        return;
    }

    StringBuffer buffer = new StringBuffer();
    while (data.moveToNext()){
        buffer.append("ID : " + data.getString(0) + "\n");
        buffer.append("Username : " + data.getString(1) + "\n");
        buffer.append("Date of Birth : " + data.getString(2) + "\n");
        buffer.append("Gender : " + data.getString(3) +  "\n");
    }

    showMessage("User Details", buffer.toString());

}

public void showMessage(String title, String message){
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(true);
    builder.setTitle(title);
    builder.setMessage(message);
    builder.show();
}

public void onClickEdit(View view){
    boolean success = dbHelper.updateInfo(userName.getText().toString(), password.getText().toString(), dob.getText().toString(), gender);
    Toast.makeText(EditProfileActivity.this, "Info Update Success: " + success, Toast.LENGTH_LONG).show();
}

public void onRadioButtonClicked(View view){
    boolean checked = ((RadioButton) view).isChecked();

    switch (view.getId()){
        case R.id.MaleRadioButton:
            if (checked)
                gender = "Male";
            break;

        case R.id.FemaleRadioButton:
            if (checked)
                gender = "Female";
            break;
    }
}

}

// Менеджер профилей

public class ProfileManagementActivity extends AppCompatActivity {

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

public void onClickUpdateProfile(View view){
    Intent intent = new Intent(ProfileManagementActivity.this, EditProfileActivity.class);
    startActivity(intent);
}

}

0 голосов
/ 15 октября 2018
//DBHelper class
public class DBHelper extends SQLiteOpenHelper {

public static final String DATABASE_NAME = "UserInformation.db";

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

@Override
public void onCreate(SQLiteDatabase db) {
    String SQL_CREATE_ENTRIES = "CREATE TABLE "
            + UserProfile.Users.TABLE_NAME + " ("
            + UserProfile.Users._ID + "INTEGER PRIMARY KEY AUTOINCREMENT,"
            + UserProfile.Users.COLUMN_NAME_USERNAME + "TEXT,"
            + UserProfile.Users.COLUMN_NAME_PASSWORD + "TEXT,"
            + UserProfile.Users.COLUMN_NAME_DATEOFBIRTH + "TEXT,"
            + UserProfile.Users.COLUMN_NAME_GENDER + "TEXT)";

    db.execSQL(SQL_CREATE_ENTRIES);

}

@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
    db.execSQL("drop table if exists " + UserProfile.Users.TABLE_NAME);

}

public boolean addInfo(String username, String password, String dob, String gender){
    SQLiteDatabase db = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(UserProfile.Users.COLUMN_NAME_USERNAME, username);
    values.put(UserProfile.Users.COLUMN_NAME_PASSWORD, password);
    values.put(UserProfile.Users.COLUMN_NAME_DATEOFBIRTH, dob);
    values.put(UserProfile.Users.COLUMN_NAME_GENDER, gender);

    int i  = (int) db.insert(UserProfile.Users.TABLE_NAME, null, values);

    if(i > 0)
        return true;
    else
        return false;
}

public boolean updateInfor(String username, String password, String dob, String gender){

    SQLiteDatabase db = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(UserProfile.Users.COLUMN_NAME_USERNAME, username);
    values.put(UserProfile.Users.COLUMN_NAME_PASSWORD, password);
    values.put(UserProfile.Users.COLUMN_NAME_DATEOFBIRTH, dob);
    values.put(UserProfile.Users.COLUMN_NAME_GENDER, gender);

    String selection = UserProfile.Users.COLUMN_NAME_USERNAME + " LIKE ?";
    String[] selectionArgs = { username };

    int i = db.update(
            UserProfile.Users.TABLE_NAME,
            values,
            selection,
            selectionArgs
    );

    if(i > 0)
        return true;
    else
        return false;

}

public Cursor readAllInfor(){
    SQLiteDatabase db = getWritableDatabase();

    Cursor cursor = db.rawQuery("select * from " + UserProfile.Users.TABLE_NAME + "",null);
    return cursor;
}

public Cursor readAllInfor(String username){

    SQLiteDatabase db = getWritableDatabase();

    Cursor cursor = db.rawQuery("select * from " + UserProfile.Users.TABLE_NAME + "where " + UserProfile.Users.COLUMN_NAME_USERNAME+"=\""+username+"\"", null);
    return cursor;
}

public boolean deleteInfo(String username){
    SQLiteDatabase db = getWritableDatabase();

    String selection = UserProfile.Users.COLUMN_NAME_USERNAME + " LIKE ?";
    String[] selectionArgs = { username };

    int i = db.delete(
            UserProfile.Users.TABLE_NAME,
            selection,
            selectionArgs
    );

    if(i > 0)
        return true;
    else
        return false;
}
}

//Edit Profile class

public class EditProfileActivity extends AppCompatActivity {

private EditText username, password, dob;
private RadioGroup gender;
private RadioButton male, female;
private Button edit, delete, search;
DBHelper db;

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

    username = (EditText) findViewById(R.id.epusernameedittext);
    dob = (EditText) findViewById(R.id.epdateofbirthedittext);
    password = (EditText) findViewById(R.id.eppasswordedittext);
    gender = (RadioGroup) findViewById(R.id.epagender);
    male = (RadioButton) findViewById(R.id.epmale);
    female = (RadioButton) findViewById(R.id.epfemale);
    edit = (Button) findViewById(R.id.epedit);
    delete = (Button) findViewById(R.id.epdelete);
    search = (Button) findViewById(R.id.epsearch);
    final String radiobuttonid = String.valueOf(gender.getCheckedRadioButtonId());
    db = new DBHelper(this);

    search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Cursor cursor = db.readAllInfor(username.getText().toString());
            int i = cursor.getCount();

            if(i <= 0){
                Toast.makeText(EditProfileActivity.this, "User not found", Toast.LENGTH_LONG).show();
            }
            while (cursor.moveToNext()){
                dob.setText(cursor.getString(2));
                if(cursor.getString(3).toString().matches("Male")){
                    male.setChecked(true);
                }
                else{
                    female.setChecked(true);
                }
                password.setText(cursor.getString(4));
            }
        }
    });

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean isInserted = db.updateInfor(
                    username.getText().toString(),
                    dob.getText().toString(),
                    password.getText().toString(),
                    radiobuttonid
            );

            if(isInserted == true)
                Toast.makeText(EditProfileActivity.this, "Data Inserted", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(EditProfileActivity.this, "DAta not Added", Toast.LENGTH_LONG).show();
        }
    });

    delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean isInserted = db.deleteInfo(
                    username.getText().toString()
            );

            if(isInserted == true)
                Toast.makeText(EditProfileActivity.this, "Data Inserted", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(EditProfileActivity.this, "DAta not Added", Toast.LENGTH_LONG).show();
        }
    });

    db.close();

}
}

//Home Activity

public class HomeActivity extends AppCompatActivity {

private final AppCompatActivity activity = HomeActivity.this;

private EditText username, password;
private RadioButton male, female;
Button login, register;

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

    username = (EditText) findViewById(R.id.usernameedittext);
    password = (EditText) findViewById(R.id.passwordedittext);
    register = (Button) findViewById(R.id.register);
    login = (Button) findViewById(R.id.login);

    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            registerClick();
        }
    });

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

            loginClick();

        }
    });

}

private void loginClick() {
    Intent intent = new Intent(HomeActivity.this, EditProfileActivity.class);
    startActivity(intent);


}

private void registerClick() {
    Intent intent = new Intent(HomeActivity.this, ProfileManagementActivity.class);
    startActivity(intent);
}




}

//profile management

public class ProfileManagementActivity extends AppCompatActivity {

private EditText username, password, dob;
private Button register;
private RadioGroup gender;
DBHelper db;

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

    username = (EditText) findViewById(R.id.prusernameedittext);
    dob = (EditText) findViewById(R.id.prdateofbirthedittext);
    password = (EditText) findViewById(R.id.prpasswordedittext);
    register = (Button) findViewById(R.id.prupdate);
    gender = (RadioGroup) findViewById(R.id.pragender);
    final String radiobuttonid = String.valueOf(gender.getCheckedRadioButtonId());
    db = new DBHelper(this);

    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean isInserted = db.addInfo(
                    username.getText().toString(),
                    password.getText().toString(),
                    dob.getText().toString(),
                    radiobuttonid
            );

            if(isInserted == true)
                Toast.makeText(ProfileManagementActivity.this, "Data Inserted", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(ProfileManagementActivity.this, "DAta not Added", Toast.LENGTH_LONG).show();
        }
    });

    db.close();
}
}

//user profile

public final class UserProfile {
private UserProfile(){}

public static class Users implements BaseColumns{

    public static final String TABLE_NAME = "Users";
    public static final String COLUMN_NAME_USERNAME = "username";
    public static final String COLUMN_NAME_PASSWORD = "password";
    public static final String COLUMN_NAME_DATEOFBIRTH = "date_of_birth";
    public static final String COLUMN_NAME_GENDER = "gender";
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...