0% found this document useful (0 votes)
3 views4 pages

Program 10-3

The document outlines a user registration application that collects user details such as name, email, and password through an Android interface. It includes XML layout for the user input fields and a Java class that handles the registration logic, including database storage using SQLite. The application validates input and provides feedback on registration success or failure.

Uploaded by

shivgond419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Program 10-3

The document outlines a user registration application that collects user details such as name, email, and password through an Android interface. It includes XML layout for the user input fields and a Java class that handles the registration logic, including database storage using SQLite. The application validates input and provides feedback on registration success or failure.

Uploaded by

shivgond419
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Program 10 :

Create a user registration application that stores the


user details in a database table.
Xml :

<?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:orientation="vertical"
android:padding="16dp">

<EditText
android:id="@+id/editName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name" />

<EditText
android:id="@+id/editEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email" />

<EditText
android:id="@+id/editPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />

<Button
android:id="@+id/btnRegister"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />

</LinearLayout>
MainActivity.java :

package com.example.tenprog;
import android.content.*;
import android.database.sqlite.*;
import android.os.*;
import android.widget.*;
import androidx.appcompat.app.*;
public class MainActivity extends AppCompatActivity {
EditText n,e,p;SQLiteDatabase d;
protected void onCreate(Bundle
b){super.onCreate(b);setContentView(R.layout.activity_main);
n=findViewById(R.id.editName); e=findViewById(R.id.editEmail);
p=findViewById(R.id.editPassword);
d=new DbHelper(this).getWritableDatabase();
findViewById(R.id.btnRegister).setOnClickListener(v->r());
}
void r(){
String N=n.getText().toString(),E=e.getText().toString(),P=p.getText().toString();
if(N.isEmpty()||E.isEmpty()||P.isEmpty()){Toast.makeText(this,"Fill all
fields",Toast.LENGTH_SHORT).show();return;}
ContentValues v=new
ContentValues();v.put("name",N);v.put("email",E);v.put("password",P);
if(d.insert("users",null,v)!=-
1){Toast.makeText(this,"Success",Toast.LENGTH_SHORT).show();n.setText("");e.setText("");
p.setText("");}
else Toast.makeText(this,"Failed",Toast.LENGTH_SHORT).show();
}
class DbHelper extends SQLiteOpenHelper{
DbHelper(Context c){super(c,"userdb",null,1);
}
public void onCreate(SQLiteDatabase d){
d.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY,name TEXT,email
TEXT,password TEXT)");
}
public void onUpgrade(SQLiteDatabase d,int o,int n){
d.execSQL("DROP TABLE IF EXISTS users");onCreate(d);
}
}
}

You might also like