Code section from Create Account Screen (.java)
String userName=createUserNameText.getText().toString(); String password=createPasswordText.getText().toString(); String confirmPassword=createPasswordConfirmText.getText().toString(); String takenUserName= loginDataBaseAdapter.getSingleEntry(userName); if(userName.equals(takenUserName)) { Toast.makeText(getApplicationContext(), "UserName Already Taken", Toast.LENGTH_LONG).show(); return; } // check if any of the fields are vacant if(userName.equals("")||password.equals("")||confirmPassword.equals("")) { Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show(); return; } // check if both password matches if(!password.equals(confirmPassword)) { Toast.makeText(getApplicationContext(), "Password does not match", Toast.LENGTH_LONG).show(); return; } else { // Save the Data in Database loginDataBaseAdapter.insertEntry(userName, password); Toast.makeText(getApplicationContext(), "Account Successfully Created ", Toast.LENGTH_LONG).show();
Account Screen
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/question_mark_background" android:orientation="vertical" > <EditText android:id="@+id/createAccountScreenInputUserName" android:hint="User Name" android:layout_width="match_parent" android:layout_height="wrap_content" > <requestFocus /> </EditText> <EditText android:id="@+id/createAccountScreenInputPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Password" android:inputType="textPassword" /> <EditText android:id="@+id/createAccountScreenInputConfirmPassword" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="Confirm Password" android:inputType="textPassword" /> <Button android:id="@+id/createAccountScreenCreateAccountButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Create Account" android:layout_marginBottom="50dp" /> </LinearLayout>
Code Section from Data Base Adapter (.java)
public void insertEntry(String userName,String password) { ContentValues newValues = new ContentValues(); // Assign values for each row. newValues.put("USERNAME", userName); newValues.put("PASSWORD",password); // Insert the row into your table db.insert("LOGIN", null, newValues); ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show(); } public int deleteEntry(String UserName) { //String id=String.valueOf(ID); String where="USERNAME=?"; int numberOFEntriesDeleted= db.delete("LOGIN", where, new String[]{UserName}) ; // Toast.makeText(context, "Number for Entry Deleted Successfully : "+numberOFEntriesDeleted, Toast.LENGTH_LONG).show(); return numberOFEntriesDeleted; } public String getSingleEntry(String userName) { Cursor cursor=db.query("LOGIN", null, " USERNAME=?", new String[]{userName}, null, null, null); if(cursor.getCount()<1) // UserName Not Exist { cursor.close(); return "NOT EXIST"; } cursor.moveToFirst(); String password= cursor.getString(cursor.getColumnIndex("PASSWORD")); cursor.close(); return password; } public void updateEntry(String userName,String password) { // Define the updated row content. ContentValues updatedValues = new ContentValues(); // Assign values for each row. updatedValues.put("USERNAME", userName); updatedValues.put("PASSWORD",password); String where="USERNAME = ?"; db.update("LOGIN",updatedValues, where, new String[]{userName}); } }