Registration screen

Asked

Viewed 30 times

0

I have a log screen, which compares the edittext text with the database field, and this comparison is working normally.

What I would like to do, is that if there was already the field of email in the bank, the activity does not continue.

Code:

 mEmail = email.getText().toString();

        new getUser().execute();




        btnfincad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                if (("".equals(email.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                } else if (("".equals(password.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                } else if (("".equals(nick.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                } else if (("".equals(number.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                } else if (("".equals(sexo.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                } else if (("".equals(data.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                } else if (("".equals(number.getText().toString().trim()))) {
                    Toast.makeText(PostCadastro.this, "Nenhum campo pode ser nulo !", Toast.LENGTH_LONG).show();
                    return;
                }






                mName = name.getText().toString();
                mNick = nick.getText().toString();
                mPassword = password.getText().toString();
                mNumber = number.getText().toString();
                mSexo = sexo.getText().toString();
                mData = data.getText().toString();
                mEmail = email.getText().toString();

Man return that doesn’t work properly is this:

  protected void onPostExecute(final String result) {

           super.onPostExecute(result);


           try {

               JSONObject json = new JSONObject(result);

               JSONArray array = new JSONArray(json.getString("resource"));
               for (int i = 0; i < array.length(); i++) {

                   JSONObject jsonObj = array.getJSONObject(i);

                   String email = jsonObj.getString("tx_email");
                   System.out.println(email);


                   if (mEmail.equals(email)) {
                       Toast.makeText(PostCadastro.this, "Email já existe", Toast.LENGTH_LONG).show();
                        return ;


                   }
               }


           } catch (JSONException e) {
               e.printStackTrace();
           }

       }
  • How come it doesn’t work? Isn’t it called or doesn’t come out of the method? Maybe what you need is the break; instead of return;

  • Even with the break does not work, ?

  • You have an asynchronous call that you can’t get the main thread to wait for that call. You’ll have to deal with it on the return of that call. If email is invalid does not go to next screen.

  • How can I solve this ? I’m an intern on Android

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.