@Override
public void onClick(View v) {
if (v == Register) {
registerUser();
}
}
private void registerUser() {
int selectedId = Gender.getCheckedRadioButtonId();
Selection = (RadioButton) findViewById(selectedId);
if (Name.getText().toString().equals("")) {
Name.setError("Enter your name");
Name.requestFocus();
} else if (Dob.getText().toString().equals("")) {
Dob.setError("Enter Date of Birth");
Dob.requestFocus();
} else if (Collegeid.getText().toString().equals("")) {
Collegeid.setError("Enter your CollegeID");
Collegeid.requestFocus();
} else if (Education.getSelectedItem().toString().equals("")) {
Toast.makeText(RegisterFormActivity.this, "choose your education", Toast.LENGTH_SHORT).show();
} else if (Year.getText().toString().equals("")) {
Year.setError("Enter Year");
Year.requestFocus();
} else if (Address.getText().toString().equals("")) {
Address.setError("Enter Your Address");
Address.requestFocus();
} else if (Pincode.getText().toString().equals("")) {
Pincode.setError("Enter Pincode");
Pincode.requestFocus();
} else if (Mobile.getText().toString().equals("")) {
Mobile.setError("Enter your Mobile Number");
Mobile.requestFocus();
} else if (!validatePhone(Mobile.getText().toString())) {
Mobile.setError("Invalid Mobile Number");
Mobile.requestFocus();
} else if (landline.getText().toString().equals("")) {
landline.setError("Enter your landline Number");
landline.requestFocus();
} else if (Email.getText().toString().equals("")) {
Email.setError("Enter your email");
Email.requestFocus();
} else if (Fbid.getText().toString().equals("")) {
Fbid.setError("Enter your facebookId");
Fbid.requestFocus();
} else if (Occupation.getSelectedItem().toString().equals("")) {
Toast.makeText(RegisterFormActivity.this, "Fathers occupation", Toast.LENGTH_SHORT).show();
}
else if(Selection.getText().toString().equals(""))
{
Toast.makeText(RegisterFormActivity.this, "choose your gender", Toast.LENGTH_SHORT).show();
}
else if (Business.getText().toString().equals("")) {
Business.setError("please specify details");
Business.requestFocus();
} else if (Shortgoal.getText().toString().equals("")) {
Shortgoal.setError("Your short term goal");
Shortgoal.requestFocus();
} else if (Longgoal.getText().toString().equals("")) {
Longgoal.setError("Your long term goal");
Longgoal.requestFocus();
} else if (Size.getText().toString().equals("")) {
Size.setError("Enter T-shirt Size");
Size.requestFocus();
} else if (Reference.getText().toString().equals("")) {
Size.setError("Enter Reference name");
Size.requestFocus();
}
else if(Form.getText().toString().equals("")){
Form.setText("Enquiry Form");
}
else {
String sname = Name.getText().toString().trim();
String dob = Dob.getText().toString().trim();
String cid = Collegeid.getText().toString().trim();
String edu = Education.getSelectedItem().toString();
String year = Year.getText().toString().trim();
String addr = Address.getText().toString().trim();
String pin = Pincode.getText().toString().trim();
String mob = Mobile.getText().toString().trim();
String lan = landline.getText().toString().trim();
String email = Email.getText().toString().trim();
String fbid = Fbid.getText().toString().trim();
String focc = Occupation.getSelectedItem().toString();
String bus= Selection.getText().toString().trim();
String spe = Business.getText().toString().trim();
String stgoal = Shortgoal.getText().toString().trim();
String ltgoal = Longgoal.getText().toString().trim();
String tsize = Size.getText().toString().trim();
//long tick_no = id.getText()
sub = Form.getText().toString().trim();
// String ref = Reference.getText().toString().trim();
// String gender = Selection.getSelected().toString().toLowerCase();
register(sname, dob, cid, edu, year, addr, pin, mob, lan, email, fbid, focc, bus, spe, stgoal, ltgoal, tsize, ref);
msg = "<p><b>Name: </b>" + sname + "</p><p><b>Dob: </b>" + dob +
"</p><p><b>Collegeid: </b>" + cid +"</p><p><b>Education: </b>" + edu +"</p><p><b>Year: </b>" + year +
"</p><p><b>Address: </b>" + addr +"</p><p><b>Pincode: </b>" + pin +"</p><p><b>Mobile: </b>" + mob +"</p><p><b>landline: </b>" + lan +"</p><p><b>Email: </b>" + email +
"</p><p><b>Fbid: </b>" + fbid +"</p><p><b>Occupation: </b>" + focc +"</p><p><b>Selection: </b>" + bus +"</p><p><b>Business: </b>" + spe +"</p><p><b>Shortgoal: </b>" + stgoal +
"</p><p><b>Longgoal: </b>" + ltgoal +"</p><p><b>Size: </b>" + tsize +
"</p><p><b>Reference: </b>" + Reference.getText().toString();
Properties props = new Properties();
props.put("mail.smtp.host", "md-in-13.webhostbox.net");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password");
}
});
if(DetectConnection
.checkInternetConnection(RegisterFormActivity.this)){
//Toast.makeText(RegisterFormActivity.this, "mailn", Toast.LENGTH_LONG).show();
RetrieveFeedTask task = new RetrieveFeedTask();
task.execute();
}
else
{
Toast.makeText(RegisterFormActivity.this, "No internet connection", Toast.LENGTH_LONG).show();
}
}
}
private void register(String sname, String dob, String cid, String edu, String year, String addr, String pin, String mob, String lan, String email, String fbid, String focc, String bus, String spe, String stgoal, String ltgoal, String tsize, String ref) {
String urlSuffix = "?sname=" + sname + "&dob=" + dob + "&cid=" + cid + "&edu=" + edu + "&year=" + year + "&email=" + email + "&mob=" + mob + "&addr=" + addr + "&lan=" + lan + "&pin=" + pin + "&fbid=" + fbid + "&focc=" + focc + "&bus=" + bus + "&spe=" + spe + "&stgoal=" + stgoal + "<goal=" + ltgoal + "&tsize=" + tsize + "&ref=" + ref;
class RegisterUser extends AsyncTask<String, Void, String> {
ProgressDialog loading;
@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(RegisterFormActivity.this, "Please Wait", null, true, true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
loading.dismiss();
if (s.equals("1")) {
Toast.makeText(RegisterFormActivity.this, "success", Toast.LENGTH_SHORT).show();
Name.setText("");
Email.setText("");
} else if (s.equals("0")) {
Toast.makeText(RegisterFormActivity.this, "Something went wrong", Toast.LENGTH_SHORT).show();
}
// Toast.makeText(getApplicationContext(), s, Toast.LENGTH_LONG).show();
}
@Override
protected String doInBackground(String... params) {
String s = params[0];
BufferedReader bufferedReader = null;
try {
URL url = new URL(REGISTER_URL + s);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String result;
result = bufferedReader.readLine();
return result;
} catch (Exception e) {
return null;
}
}
}
RegisterUser ru = new RegisterUser();
ru.execute(urlSuffix);
}
In this I have made the connection with db. I need to display a alert or toast in postExecute
by checking 1 to display success and 0 for display error. My form is successfully storing in db but I'm not able to show any success or error after the progress loading finished.