i have to two table "OWNER" and "USER" on selecting the first radio button it save the data on user table and on selecting second radio button data will be save on owner table
database helper class which contain the function to create the user table and owner table and insertdataUse insertdataOwner funtion to insert the data in table
here is my singup page in which we have two function adddatauser to user and adddataowner to
public class SinGUP extends AppCompatActivity {
Databasehelper myDB; EditText et_name,et_pnumber,et_email,et_password; private static Button btnsignup; String name,pnumber,email,password; RadioButton r1,r2; RadioGroup rg; public int x; TextView loginbtn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sin_gup); myDB = new Databasehelper(this); et_name=(EditText)findViewById(R.id.editText_pname); et_pnumber=(EditText)findViewById(R.id.editText_pnumber); et_password=(EditText)findViewById(R.id.editText_password); et_email=(EditText)findViewById(R.id.editText_email1); r1=(RadioButton)findViewById(R.id.radioButton_Owner); r2=(RadioButton)findViewById(R.id.radioButton_user); loginbtn=(TextView)findViewById(R.id.textView_login); //TypeOfUser(); loginbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i= new Intent(SinGUP.this,MainActivity.class); startActivity(i); } }); btnsignup=(Button)findViewById(R.id.button_singup); btnsignup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { singup(); } }); } public void singup() { initializes(); if(!Validate()) { Toast.makeText(SinGUP.this,"sigup can't be done",Toast.LENGTH_LONG).show(); } else { rg = (RadioGroup) findViewById(R.id.radiogroup); int selectOptId = rg.getCheckedRadioButtonId(); r1 = (RadioButton) findViewById(selectOptId); Toast.makeText(getApplicationContext(), r1.getText(), Toast.LENGTH_SHORT).show(); if (r1.getText() == "radioButton_user") Adddatauser(); if (r1.getText() == "radioButton_owner") AdddataOwner(); } } public void initializes() { name=et_name.getText().toString().trim(); pnumber=et_pnumber.getText().toString().trim(); email=et_email.getText().toString().trim(); password=et_password.getText().toString().trim(); } public boolean Validate() { boolean valid=true; if(name.isEmpty()||name.length()<7){ et_name.setError("please enter the valid name"); valid=false;} if(pnumber.isEmpty()||pnumber.length()<10){ et_pnumber.setError("please enter the valid phone number"); valid=false;} if(password.isEmpty()||password.length()<7){ et_password.setError(" password length 8"); valid=false;} if(email.isEmpty()||!isValidEmail(email)){ et_name.setError("please enter the valid email"); valid=false;} return valid; }
public boolean isValidEmail(String email) { String EMAIL_PATTERN = "^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)@"+"[A-Za-z0-9-]+(\.[A-Za-z0-9]+)(\.[A-Za-z]{2,})$";
Pattern pattern = Pattern.compile(EMAIL_PATTERN); Matcher matcher = pattern.matcher(email); return matcher.matches(); } //function to add owner detail public void AdddataOwner(){ boolean inserData = myDB.insertdataOwner(name, pnumber, password, email); // boolean insertDataU = myDB.insertdataUser(name. getText().toString(), pnumber.getText().toString(), password.getText().toString(), email.getText().toString()); if (inserData == true) Toast.makeText(SinGUP.this, "data inserted owner", Toast.LENGTH_SHORT).show(); else Toast.makeText(SinGUP.this, "data canot be inserted owner", Toast.LENGTH_SHORT).show(); } //function to add user detail public void Adddatauser(){ boolean insertDataU = myDB.insertdataUser(name, pnumber, password, email); if (insertDataU==true) Toast.makeText(SinGUP.this, "data inserted user", Toast.LENGTH_SHORT).show(); else Toast.makeText(SinGUP.this, "data canot be inserted user", Toast.LENGTH_SHORT).show(); }
Change below condition
if (r1.getText() == "radioButton_user")
Adddatauser();
if (r1.getText() == "radioButton_owner")
AdddataOwner();
to
if (r1.getText().equalsIgnoreCase("radioButton_user")) {
Adddatauser();
} else if (r1.getText().equalsIgnoreCase("radioButton_owner")) {
AdddataOwner();
}