Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import customandroidtoastdemo.app.com.mad_final_end.UserProfile;
- import static android.os.Build.ID;
- import static customandroidtoastdemo.app.com.mad_final_end.UserProfile.Users.COL_1;
- import static customandroidtoastdemo.app.com.mad_final_end.UserProfile.Users.COL_2;
- import static customandroidtoastdemo.app.com.mad_final_end.UserProfile.Users.COL_3;
- import static customandroidtoastdemo.app.com.mad_final_end.UserProfile.Users.COL_4;
- import static customandroidtoastdemo.app.com.mad_final_end.UserProfile.Users.COL_5;
- /**
- * Created by Kalana on 10/13/2018.
- */
- public class DBHelper extends SQLiteOpenHelper {
- private static final String DATABASE_NAME="Users.db";
- public DBHelper(Context context) {
- super(context, DATABASE_NAME, null, 1);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(" CREATE TABLE " +
- UserProfile.Users.TABLE_NAME+" ("+
- COL_1+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
- UserProfile.Users.COL_2+" TEXT, " +
- UserProfile.Users.COL_3+" TEXT, " +
- UserProfile.Users.COL_4+" TEXT, "+
- UserProfile.Users.COL_5+" TEXT ) ") ;
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int i, int i1) {
- db.execSQL(" DROP TABLE IF EXISTS " + UserProfile.Users.TABLE_NAME);
- onCreate(db);
- }
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
- public boolean AddInfo(String uName, String dOfBth, String password, String gender){
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues contentValues=new ContentValues();
- contentValues.put(UserProfile.Users.COL_2,uName);
- contentValues.put(UserProfile.Users.COL_3,dOfBth);
- contentValues.put(UserProfile.Users.COL_4,password);
- contentValues.put(UserProfile.Users.COL_5,gender);
- try{
- long result= db.insert(UserProfile.Users.TABLE_NAME,null,contentValues);
- return true;
- }
- catch(Exception e){
- e.printStackTrace();
- return false;
- }
- }
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>..
- public Cursor readAllData(){
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor res =db.rawQuery(" select * from "+UserProfile.Users.TABLE_NAME,null);
- return res;
- }
- //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- public Cursor readSingaleData(String id){
- SQLiteDatabase db = this.getWritableDatabase();
- Cursor res =db.rawQuery(" select * from "+UserProfile.Users.TABLE_NAME+ " where "+UserProfile.Users.COL_1 + " = '" +id+ "' ",null);
- return res;
- }
- //>>>>>>>>>>>
- public Integer deleteInfo(String id){
- SQLiteDatabase db= this.getWritableDatabase();
- return db.delete(UserProfile.Users.TABLE_NAME,"id=?",new String[]{id});
- }
- public boolean update(String id,String username,String DofBth,String password,String gender){
- SQLiteDatabase db=this.getWritableDatabase();
- ContentValues contentValues= new ContentValues();
- contentValues.put(COL_1,id);
- contentValues.put(COL_2,username);
- contentValues.put(COL_3,DofBth);
- contentValues.put(COL_4,password);
- contentValues.put(COL_5,gender);
- db.update(UserProfile.Users.TABLE_NAME,contentValues,"id= ?",new String[] {id});
- return true;
- }
- }
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- public class Home extends AppCompatActivity {
- Button Reg ;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_home);
- Reg=(Button)findViewById(R.id.button_RegisterHome);
- Reg.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent startIntent = new Intent(getApplicationContext(), ProfileManagement.class);
- startActivity(startIntent);
- }
- });
- }
- }
- import android.database.Cursor;
- 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 customandroidtoastdemo.app.com.mad_final_end.Database.DBHelper;
- public class EditProfile extends AppCompatActivity {
- Button deletebtn;
- Button update;
- Button search;
- DBHelper myDB;
- EditText username,DofBth,password,id;
- RadioGroup RdioGrp;
- RadioButton Rdbtn;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_edit_profile);
- myDB = new DBHelper(this);
- id =(EditText)findViewById(R.id.editText_ID);
- username =(EditText)findViewById(R.id.editText_UserNameEdit);
- DofBth =(EditText)findViewById(R.id.editText_DofBth);
- password =(EditText)findViewById(R.id.editText_PasswordEdit);
- RdioGrp =(RadioGroup) findViewById(R.id.RdioGrp);
- deletebtn =(Button)findViewById(R.id.button_DeletePro);
- update =(Button)findViewById(R.id.button_EditPro);
- search =(Button)findViewById(R.id.button_SearchEdit);
- delete();
- update();
- readSingaleInfo();
- }
- public void delete(){
- deletebtn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Integer deletedRows = myDB.deleteInfo(id.getText().toString());
- if(deletedRows>0){
- Toast.makeText(EditProfile.this, "Data Is deleted", Toast.LENGTH_SHORT).show();
- }
- else{
- Toast.makeText(EditProfile.this,"Not deleted",Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- public void update(){
- update.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int SelectedID1= RdioGrp.getCheckedRadioButtonId();
- Rdbtn=(RadioButton)findViewById(SelectedID1);
- boolean isUpdated=myDB.update(id.getText().toString(),username.getText().toString(),DofBth.getText().toString(),password.getText().toString(),Rdbtn.getText().toString());
- if(isUpdated =true){
- Toast.makeText(EditProfile.this,"Data is Updated",Toast.LENGTH_SHORT).show();
- }
- else{
- Toast.makeText(EditProfile.this,"Data is not Updated",Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- public void readSingaleInfo( ){
- search.setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Cursor res= myDB.readSingaleData(id.getText().toString());
- if(res.getCount()==0){
- //message
- showmessage("Error","Nothing Found from System");
- return;
- }
- else{
- StringBuffer buffer= new StringBuffer();
- // we used while lopp to check all rows becasse we dont knw how many rows are there
- while(res.moveToNext()){
- buffer.append("id :"+ res.getString(0)+ "n");
- buffer.append("username :"+ res.getString(1)+ "n");
- buffer.append("DofBirth :"+ res.getString(2)+ "n");
- // buffer.append("Password :"+ res.getString(3)+ "n");
- buffer.append("Gender :"+ res.getString(4)+ "n");
- }
- showmessage("Data",buffer.toString());
- }
- }
- }
- );
- }
- public void showmessage(String title, String Message){
- android.support.v7.app.AlertDialog.Builder builder= new android.support.v7.app.AlertDialog.Builder(this);
- builder.setCancelable(true);
- builder.setTitle(title);
- builder.setMessage(Message);
- builder.show();
- }
- }
- import android.content.Intent;
- import android.database.Cursor;
- 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 customandroidtoastdemo.app.com.mad_final_end.Database.DBHelper;
- public class ProfileManagement extends AppCompatActivity {
- Button Add;
- Button View,Edit;
- EditText username,DofBth,password,id;
- RadioGroup RdioGrp;
- RadioButton Rdbtn;
- DBHelper myDB;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_profile_management);
- myDB = new DBHelper(this);
- username=(EditText)findViewById(R.id.editText_usernamePro);
- DofBth =(EditText)findViewById(R.id.editText_dOfBthPro);
- password=(EditText)findViewById(R.id.editText_passwordPro);
- RdioGrp =(RadioGroup)findViewById(R.id.RdGrp);
- Add = (Button)findViewById(R.id.button_addPro);
- View=(Button)findViewById(R.id.button_ViewPro);
- Edit=(Button)findViewById(R.id.button_EditPro);
- Edit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent startIntent = new Intent(getApplicationContext(), EditProfile.class);
- startActivity(startIntent);
- }
- });
- AddInfo();
- readAllInfo();
- }
- public void AddInfo(){
- Add.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int SelectedID= RdioGrp.getCheckedRadioButtonId();//pass the radio button value to the vairible
- Rdbtn=(RadioButton)findViewById(SelectedID);
- boolean isInserted = myDB.AddInfo(username.getText().toString(),DofBth.getText().toString(),password.getText().toString(),Rdbtn.getText().toString());
- if(isInserted=true){
- Toast.makeText(ProfileManagement.this, "Data Is Inserted", Toast.LENGTH_SHORT).show();
- }
- else{
- Toast.makeText(ProfileManagement.this,"Not Inserted",Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- public void readAllInfo(){
- View.setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Cursor res= myDB.readAllData();
- if(res.getCount()==0){
- //message
- showmessage("Error","Nothing Found from System");
- return;
- }
- else{
- StringBuffer buffer= new StringBuffer();
- // we used while lopp to check all rows becasse we dont knw how many rows are there
- while(res.moveToNext()){
- buffer.append("id :"+ res.getString(0)+ "n");
- buffer.append("username :"+ res.getString(1)+ "n");
- buffer.append("DofBirth :"+ res.getString(2)+ "n");
- // buffer.append("Password :"+ res.getString(3)+ "n");
- buffer.append("Gender :"+ res.getString(4)+ "n");
- }
- showmessage("Data",buffer.toString());
- }
- }
- }
- );
- }
- public void showmessage(String title, String Message){
- android.support.v7.app.AlertDialog.Builder builder= new android.support.v7.app.AlertDialog.Builder(this);
- builder.setCancelable(true);
- builder.setTitle(title);
- builder.setMessage(Message);
- builder.show();
- }
- }
- import android.provider.BaseColumns;
- /**
- * Created by Kalana on 10/13/2018.
- */
- public final class UserProfile {
- //default Constructer
- private UserProfile(){}
- //Inner Class
- public class Users implements BaseColumns{
- public static final String TABLE_NAME="UserInfo";
- public static final String COL_1="id";
- public static final String COL_2="username";
- public static final String COL_3="dOfBth";
- public static final String COL_4="password";
- public static final String COL_5="gender";
- }
- }
Add Comment
Please, Sign In to add comment