regpage

xml coda:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">


<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:gravity="center"
android:text="register"
android:textSize="30dp"
android:textStyle="bold" />

<ImageView
android:id="@+id/imv"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:src="@drawable/contactlogo" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"

android:hint="enter a username"
android:textSize="25dp" />
</com.google.android.material.textfield.TextInputLayout>


<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:hint="enter a name"
android:textSize="25dp" />

<EditText
android:id="@+id/num"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:hint="enter a number"
android:textSize="25dp" />

<EditText
android:id="@+id/em"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:hint="enter a email"
android:textSize="25dp" />

<EditText
android:id="@+id/dobs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:hint="enter a DOB"
android:textSize="25dp" />


<EditText
android:id="@+id/pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:hint="enter a password"
android:textSize="25dp" />

<EditText
android:id="@+id/cpass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/boder"
android:hint="conform password"
android:textSize="25dp" />


<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">

<RadioButton
android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />

<RadioButton
android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>


<CheckBox

android:id="@+id/cb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Accept Terms and Condition" />


<Button
android:id="@+id/regbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/boder"
android:text="register"
android:textSize="30dp"
android:textStyle="bold"
android:visibility="gone" />


</LinearLayout>
</ScrollView>



coda




import android.app.DatePickerDialog;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.Calendar;

public class Regdata extends AppCompatActivity {
EditText uname;
EditText mno;
EditText bday;
EditText eid;
EditText passw;
EditText cpassw;
RadioButton g1, g2;
Button reg;
CheckBox check;
int d, m, y;
String gen, un, ph, dob, em, ps, cps, chk;
Calendar calendar = Calendar.getInstance();
Spinner spn;
String city = "";
String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
String noPattern = "^[7896]\\d{9}$";
SQLiteDatabase db;


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

db = openOrCreateDatabase( "my.db", MODE_PRIVATE, null );


uname = findViewById( R.id.uname );
mno = findViewById( R.id.mno );
bday = findViewById( R.id.bday );
eid = findViewById( R.id.eid );
passw = findViewById( R.id.passw );
cpassw = findViewById( R.id.cpassw );
g1 = findViewById( R.id.male );
g2 = findViewById( R.id.femail );
reg = findViewById( R.id.reg );
check = findViewById( R.id.checkd );
spn = findViewById( R.id.spn );
bday.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
d = calendar.get( calendar.DAY_OF_MONTH );
m = calendar.get( calendar.MONTH );
y = calendar.get( calendar.YEAR );

DatePickerDialog datePickerDialog = new DatePickerDialog( Regdata.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {


bday.setText( i2 + "/" + (i1 + 1) + "/" + i );
}
}, y, m, d );


datePickerDialog.show();


}

} );
check.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {


if (b) {
reg.setVisibility( View.VISIBLE );
} else {
reg.setVisibility( View.GONE );
}
}
} );
Spinner spn;
final ArrayList<String> stringArrayList = new ArrayList<>();


spn = findViewById( R.id.spn );
stringArrayList.add( "select your city" );
stringArrayList.add( "surat" );
stringArrayList.add( "vapi" );
stringArrayList.add( "valchad" );
stringArrayList.add( "palsana" );
stringArrayList.add( "bhuj" );
stringArrayList.add( "rajkot" );
stringArrayList.add( "mandvi" );
stringArrayList.add( "palitana" );

CustomAdapter custom = new CustomAdapter( stringArrayList, Regdata.this );
spn.setAdapter( custom );


spn.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
city = stringArrayList.get( i );
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
} );


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


un = uname.getText().toString();
ph = mno.getText().toString();
dob = bday.getText().toString();
em = eid.getText().toString();
ps = passw.getText().toString();
cps = cpassw.getText().toString();


if (un.equals( "" )) {
uname.setError( "plz fill the username" );
} else if (ph.equals( "" )) {
mno.setError( "plz fill the number" );
} else if (!ph.matches( noPattern )) {
mno.setError( "plz enter valid number" );
} else if (dob.equals( "" )) {
bday.setError( "plz fill the dateof birthe" );
} else if (em.equals( "" )) {
eid.setError( "plz fill the email" );
} else if (!em.matches( emailPattern )) {
eid.setError( "plz enter valid email" );
} else if (ps.equals( "" )) {
passw.setError( "plz fill password" );
} else if (cps.equals( "" )) {
cpassw.setError( "plz fill confrompassword" );
} else if (!cps.equals( ps )) {
cpassw.setError( "plz enter valid password" );
} else if (city.equals( "select your city" )) {
Toast.makeText( Regdata.this, "Plz City Select", Toast.LENGTH_SHORT ).show();
} else {


db.execSQL( "insert into user(uname,phone,dob,email,pass,gender,city) values('" + un + "','" + ph + "','" + dob + "','" + em + "','" + ps + "','" + gen + "','" + city + "')" );
Toast.makeText( Regdata.this, "Suucessfully Registraiton", Toast.LENGTH_SHORT ).show();

}


}
} );
if (!check.isChecked()) {

Toast.makeText( Regdata.this, "Plz Terms and Condition Accept", Toast.LENGTH_SHORT ).show();
return;
}

if (g1.isChecked()) {
gen = g1.getText().toString();
} else {
gen = g1.getText().toString();
}

}

@Override
protected void onStart() {
super.onStart();
}
}

Comments

Popular posts from this blog

endless RecyclerView Adapter

The Movie Downloader