-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
205 additions
and
5 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
Registration/app/src/main/java/com/example/registration/DatabaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.example.registration; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
public class DatabaseHelper extends SQLiteOpenHelper { | ||
public static final String DATABASE_NAME = "Student.db"; | ||
public static final String TABLE_NAME = "student_table"; | ||
public static final String COL_1 = "ID"; | ||
public static final String COL_2 = "NAME"; | ||
public static final String COL_3 = "PHONE"; | ||
public static final String COL_4 = "EMAIL"; | ||
public static final String COL_5 = "USERNAME"; | ||
public static final String COL_6 = "PASSWORD"; | ||
|
||
public DatabaseHelper(Context context) { | ||
super(context, DATABASE_NAME, null, 1); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL(" create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, PHONE LONG INTEGER, EMAIL TEXT, USERNAME TEXT, PASSWORD TEXT)"); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); | ||
onCreate(db); | ||
|
||
} | ||
public boolean insertData(String name,String phone, String email, String username, String password){ | ||
SQLiteDatabase db=this.getWritableDatabase(); | ||
ContentValues contentValues=new ContentValues(); | ||
contentValues.put(COL_2,name); | ||
contentValues.put(COL_3,phone); | ||
contentValues.put(COL_4,email); | ||
contentValues.put(COL_5,username); | ||
contentValues.put(COL_6,password); | ||
long result = db.insert(TABLE_NAME,null,contentValues); | ||
if(result == -1) | ||
return false; | ||
else | ||
return true; | ||
} | ||
} |
42 changes: 40 additions & 2 deletions
42
Registration/app/src/main/java/com/example/registration/Main2Activity_newAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,52 @@ | ||
package com.example.registration; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
public class Main2Activity_newAccount extends AppCompatActivity { | ||
DatabaseHelper myDb; | ||
EditText editName, editPhone, editEmail, editUsername, editPassword; | ||
Button btnAddData; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main2_new_account); | ||
myDb=new DatabaseHelper(this); | ||
|
||
|
||
editName = findViewById(R.id.editName); | ||
editPhone = findViewById(R.id.editPhone); | ||
editEmail = findViewById(R.id.editEmail); | ||
editUsername = findViewById(R.id.editUsername); | ||
editPassword = findViewById(R.id.editPassword); | ||
btnAddData = findViewById(R.id.button_submit); | ||
|
||
AddData(); | ||
|
||
} | ||
|
||
public void AddData() { | ||
btnAddData.setOnClickListener( | ||
new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
boolean isInserted = myDb.insertData(editName.getText().toString(), | ||
editPhone.getText().toString(), editEmail.getText().toString(), | ||
editUsername.getText().toString(), editPassword.getText().toString()); | ||
if (isInserted == true) | ||
Toast.makeText(Main2Activity_newAccount.this, "Data Inserted", Toast.LENGTH_LONG).show(); | ||
else | ||
Toast.makeText(Main2Activity_newAccount.this, "Data not Inserted", Toast.LENGTH_LONG).show(); | ||
} | ||
} | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 114 additions & 3 deletions
117
Registration/app/src/main/res/layout/activity_main2_new_account.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,120 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".Main2Activity_newAccount"> | ||
tools:context=".Main2Activity_newAccount" | ||
android:orientation="vertical"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:layout_marginTop="15dp"> | ||
<TextView | ||
android:id="@+id/name" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Name" /> | ||
|
||
<EditText | ||
android:id="@+id/editName" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:hint="Name" | ||
android:inputType="textPersonName" | ||
android:text="" /> | ||
|
||
</LinearLayout> | ||
|
||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:layout_marginTop="15dp"> | ||
|
||
<TextView | ||
android:id="@+id/phone" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Phone" /> | ||
|
||
<EditText | ||
android:id="@+id/editPhone" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:inputType="textPersonName" | ||
android:text="" /> | ||
</LinearLayout> | ||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:layout_marginTop="15dp"> | ||
|
||
<TextView | ||
android:id="@+id/email" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Email" /> | ||
|
||
<EditText | ||
android:id="@+id/editEmail" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:inputType="textPersonName" | ||
android:text="" /> | ||
</LinearLayout> | ||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:layout_marginTop="15dp"> | ||
<TextView | ||
android:id="@+id/username" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Username" /> | ||
|
||
<EditText | ||
android:id="@+id/editUsername" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:inputType="textPersonName" | ||
android:text="" /> | ||
</LinearLayout> | ||
<LinearLayout | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
android:layout_marginTop="15dp"> | ||
|
||
<TextView | ||
android:id="@+id/password" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Password" /> | ||
|
||
<EditText | ||
android:id="@+id/editPassword" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:inputType="textPersonName" | ||
android:text="" /> | ||
</LinearLayout> | ||
|
||
<Button | ||
android:id="@+id/button_submit" | ||
android:layout_marginTop="15dp" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Submit" /> | ||
|
||
|
||
</LinearLayout> |