Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>this worked:</p> <pre><code>public class RegisterActivity extends Activity{ EditText reg_fullname; EditText reg_email; EditText reg_login; EditText reg_password; EditText reg_password2; Spinner reg_country; Spinner reg_genre; EditText reg_birthday; EditText reg_promocode; Button btnRegister; Context ctx = this; ProgressDialog pDialog; JSONArray json; String status; String msg; String fullname; String email; String login; String password; String password2; String country; String genre; String birthday; String promocode; boolean finishActivity = false; /** * @see android.app.Activity#onCreate(Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.register); TextView loginScreen = (TextView) findViewById(R.id.link_to_login); loginScreen.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { // Closing registration screen // Switching to Login Screen/closing register screen finish(); } }); reg_fullname = (EditText) findViewById(R.id.reg_fullname); reg_email = (EditText) findViewById(R.id.reg_email); reg_login = (EditText) findViewById(R.id.reg_login); reg_password = (EditText) findViewById(R.id.reg_password); reg_password2 = (EditText) findViewById(R.id.reg_password2); //confirmação de senha reg_country = (Spinner) findViewById(R.id.reg_country); reg_genre = (Spinner) findViewById(R.id.reg_genre); reg_birthday = (EditText) findViewById(R.id.reg_birthday); reg_promocode = (EditText) findViewById(R.id.reg_promocode); btnRegister = (Button) findViewById(R.id.btnRegister); btnRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { fullname = reg_fullname.getText().toString(); email = reg_email.getText().toString(); login = reg_login.getText().toString(); password = reg_password.getText().toString(); password2 = reg_password2.getText().toString(); country = reg_country.getSelectedItem().toString(); genre = reg_genre.getSelectedItem().toString(); birthday = reg_birthday.getText().toString(); promocode = reg_promocode.getText().toString(); boolean validation = true; String message = "Campo de preencimento obrigatório"; if(fullname.equalsIgnoreCase("")){ reg_fullname.setError(message); validation = false; } if(email.equalsIgnoreCase("")){ reg_email.setError(message); validation = false; } if(!email.matches(".*@.*")){ reg_email.setError("O endereço de email não é válido"); validation = false; } if(login.equalsIgnoreCase("")){ reg_login.setError(message); validation = false; } if(password.equalsIgnoreCase("")){ reg_password.setError(message); validation = false; } if(password2.equalsIgnoreCase("")){ reg_password2.setError(message); validation = false; } if(!password.equals(password2)){ reg_password2.setError("A confirmação de senha não confere"); validation = false; } if(birthday.equalsIgnoreCase("")){ reg_birthday.setError(message); validation = false; } SimpleDateFormat bd = new SimpleDateFormat("dd/MM/yyyy"); if(bd.parse(birthday, new ParsePosition(0)) == null){ reg_birthday.setError("Esta data não é válida! Preencha novamente, usando o formato dd/mm/aaaa"); validation = false; } if(validation){ new Register().execute(); } } }); } class Register extends AsyncTask&lt;Void, Void, JSONArray&gt;{ @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(ctx); pDialog.setMessage("Aguarde..."); pDialog.setIndeterminate(true); pDialog.setCancelable(false); pDialog.show(); } @Override protected JSONArray doInBackground(Void... params) { UserFunctions userFunction = new UserFunctions(); json = userFunction.newUser(fullname, email, login, password, country, genre, birthday, promocode); return json; } protected void onPostExecute(JSONArray result) { // dismiss the dialog once done pDialog.dismiss(); final AlertDialog alertDialog = new AlertDialog.Builder( RegisterActivity.this).create(); try { status = json.getString(0); msg = json.getString(1); Log.d("Status", status); } catch (JSONException e) { Log.e("RegisterActiviry", "Error converting result " + e.toString()); e.printStackTrace(); status = null; } if (status.equalsIgnoreCase("erro")){ alertDialog.setTitle("Erro"); alertDialog.setMessage(msg); }else if (status.equalsIgnoreCase("sucesso")){ alertDialog.setTitle("Sucesso!"); alertDialog.setMessage(msg); finishActivity = true; }else{ alertDialog.setTitle("Erro"); alertDialog.setMessage("Não foi possível realizar seu cadastro, tente novamente mais tarde."); } alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if(finishActivity){ finish(); }else{ alertDialog.dismiss(); } } }); alertDialog.show(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload