Ver mensagens sem resposta | Ver tópicos ativos Hoje é 06 Dez 2019, 04:09



Responder Tópico  [ 1 Mensagem ] 
 Ajuda com atualizar cadastro, consulta e gravação no DB 
Autor Mensagem
What is Android?
What is Android?

Data de registro: 17 Abr 2018, 03:47
Mensagens: 2
Mensagem Ajuda com atualizar cadastro, consulta e gravação no DB
Gostaria de uma ajuda, quando eu entro em atualizar dados o campo somente a data de nascimento não me retorna nenhum valor e quando eu coloco qualquer data e mando atualizar ele duplica o usuário, tudo isso começou quando eu inseri o código a baixo em vermelho.
segue o código abaixo:

ChangeRegisterActivity.java

public class ChangeRegisterActivity extends BaseActivity {

    private static final String TAG = ChangeRegisterActivity.class.getSimpleName();

    ImageView pictureImageView;
    EditText nameEditText;
    CpfEditText cpfEditText;
    EmailEditText emailEditText;
    EditText dddEditText;
    EditText phoneNumberEditText;
    DateEditText birthdayEditText;
    EditText addressEditText;
    EditText numberEditText;
    EditText complementEditText;
    EditText neighborhoodEditText;
    Spinner stateSpinner;
    EditText cityEditText;

    Button saveButton;

    private TextWatcher mTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            validateInput();
        }
    };

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

        Toolbar toolbarView = findViewById(R.id.toolbar);

        if (null != toolbarView) {
            setSupportActionBar(toolbarView);

            ActionBar actionBar = getSupportActionBar();
            if (actionBar != null) {

                actionBar.setDisplayShowTitleEnabled(false);
                actionBar.setDisplayHomeAsUpEnabled(true);

            }
        }

        User user = Preferences.getUser(this);

        if(user != null) {
            pictureImageView = findViewById(R.id.picture_img);
            nameEditText = findViewById(R.id.complete_name);
            cpfEditText = findViewById(R.id.cpf);
            emailEditText = findViewById(R.id.email);
            dddEditText = findViewById(R.id.ddd);
            phoneNumberEditText = findViewById(R.id.phone_number);
            birthdayEditText = findViewById(R.id.birthday);
            addressEditText = findViewById(R.id.address);
            numberEditText = findViewById(R.id.address_number);
            complementEditText = findViewById(R.id.complement);
            neighborhoodEditText =findViewById(R.id.neighborhood);
            stateSpinner = findViewById(R.id.state);
            cityEditText =findViewById(R.id.city);
            saveButton = findViewById(R.id.save_button);

            nameEditText.addTextChangedListener(mTextWatcher);
            cpfEditText.addTextChangedListener(mTextWatcher);
            emailEditText.addTextChangedListener(mTextWatcher);
            dddEditText.addTextChangedListener(mTextWatcher);
            phoneNumberEditText.addTextChangedListener(mTextWatcher);
            birthdayEditText.addTextChangedListener(mTextWatcher);
            addressEditText.addTextChangedListener(mTextWatcher);
            numberEditText.addTextChangedListener(mTextWatcher);
            neighborhoodEditText.addTextChangedListener(mTextWatcher);
            cityEditText.addTextChangedListener(mTextWatcher);

            nameEditText.setText(user.getName());
            cpfEditText.setText(user.getCpf());
            emailEditText.setText(user.getEmail());
            dddEditText.setText(user.getPhoneCode());
            phoneNumberEditText.setText(user.getPhone());
            birthdayEditText.SetText(user.getBirthday());
            addressEditText.setText(user.getAddressStreet());
            numberEditText.setText(user.getAddressNumber());
            complementEditText.setText(user.getAddressComplement());
            neighborhoodEditText.setText(user.getAddressNeighborhood());
            selectSpinnerValue(stateSpinner, user.getAddressState());
            cityEditText.setText(user.getAddressCity());

        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        Bitmap pictureBitmap = ImageUtil.getBitmapFromFile(getExternalFilesDir(null).getAbsolutePath() + "/pic.jpg");
        Resources res = getResources();
        RoundedBitmapDrawable dr = RoundedBitmapDrawableFactory.create(res, pictureBitmap);
        dr.setCircular(true);
        pictureImageView.setImageDrawable(dr);
    }

    private void selectSpinnerValue(Spinner spinner, String myString) {
        for(int i = 0; i < spinner.getCount(); i++){
            if(spinner.getItemAtPosition(i).toString().equals(myString)){
                spinner.setSelection(i);
                break;
            }
        }
    }

    private void validateInput() {
        boolean hasName = nameEditText.length() > 0;
        boolean hasCpf = cpfEditText.isValid();
        boolean hasEmail = emailEditText.length() > 0 && emailEditText.isValid();
        boolean hasPhoneCode = dddEditText.length() > 0;
        boolean hasPhone = phoneNumberEditText.length() > 0;
        boolean hasBirthday = birthdayEditText.isValidDate();

        boolean hasStreet = addressEditText.length() > 0;
        boolean hasNumber = numberEditText.length() > 0;
        boolean hasNeighborhood = neighborhoodEditText.length() > 0;
        boolean hasCity = cityEditText.length() > 0;
        boolean hasState = ((String) stateSpinner.getSelectedItem()).length() > 0;

        if (hasName && hasCpf && hasEmail && hasPhone && hasPhoneCode && hasBirthday && hasStreet &&
                hasNumber && hasNeighborhood && hasCity && hasState) {
            saveButton.setEnabled(true);
        } else {
            saveButton.setEnabled(false);
        }
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        switch (id) {
            case android.R.id.home:
                this.finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    public void editPicture(View view) {
        Intent intent = new Intent(ChangeRegisterActivity.this, RegisterPhotoActivity.class);
        intent.putExtra(RegisterPhotoActivity.CHANGE_PICTURE_EXTRA, true);

        startActivity(intent);
    }

    public void save(View view) {
        User user = buildUser();
        if(NetworkUtils.hasInternetConnection(this)) {
            new RegisterAsyncTask().execute(user.toJsonString());
        } else {
            Toast.makeText(this, R.string.no_internet_msg, Toast.LENGTH_LONG).show();
        }
    }

    private User buildUser() {
        User user = new User();
        user.setName(nameEditText.getText().toString());
        user.setCpf(cpfEditText.getText().toString());
        user.setEmail(emailEditText.getText().toString());
        user.setPhoneCode(dddEditText.getText().toString());
        user.setPhone(phoneNumberEditText.getText().toString());
        user.setBirthday(birthdayEditText.getText().toString());
        user.setAddressStreet(addressEditText.getText().toString());
        user.setAddressNumber(numberEditText.getText().toString());
        user.setAddressNeighborhood(neighborhoodEditText.getText().toString());
        user.setAddressCity(cityEditText.getText().toString());
        user.setAddressState((String) stateSpinner.getSelectedItem());
        return user;
    }

    private class RegisterAsyncTask extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... strings) {
            String userJsonObject = strings[0];

            try {
                URL url = NetworkUtils.getUserRegisterURL();

                return NetworkUtils.doPost(url, userJsonObject);
            } catch (MalformedURLException e) {
                Log.e(TAG, "MalformedURLException while trying to register the user", e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(String response) {
            super.onPostExecute(response);

            if(TextUtils.isEmpty(response)) {
                Toast.makeText(ChangeRegisterActivity.this, R.string.change_register_error_msg, Toast.LENGTH_LONG).show();
                return;
            }

            try {
                JSONObject responseJson = new JSONObject(response);
                int status = responseJson.getInt("status");

                if(status == 200) {
                    User user = new User(responseJson.getJSONObject("user"));
                    Preferences.saveUser(ChangeRegisterActivity.this, user);
                    ChangeRegisterActivity.this.finish();
                } else {
                    // TODO show dialog handling error
                    Toast.makeText(ChangeRegisterActivity.this, responseJson.getString("message"), Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                Log.e(TAG, "JSONException while parsing change register response", e);
                FirebaseCrash.report(e);
            }
        }
    }
}

 

activivity_change_register.xml

<android.support.design.widget.TextInputLayout
                android:id="@+id/birthday_input"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/phone_number_input"
                android:layout_marginTop="8dp"
                >
                <com.android.faced.view.DateEditText
                    android:id="@+id/birthday"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:hint="@string/birthday_hint"
                    android:inputType="text"
                    android:maxLines="1"
                    android:nextFocusForward="@id/address_input"
                    />
            </android.support.design.widget.TextInputLayout>


Você não tem permissões suficientes para ver os arquivos anexados nesta mensagem.


18 Abr 2018, 18:14
Perfil
Mostrar mensagens anteriores:  Organizar por  
Responder Tópico   [ 1 Mensagem ] 

Quem está online

Usuários vendo este fórum: abruzzi, adelar, Alan Unger, alansousa, albinoneto, Alexandre de Queiroz, Alexandrercarvalho, Alexsandro Tirloni, alsimoes, aluclinux, alylson, amarildolacerdas, Andrey, Aniquiler, Aparec, Ask Jeeves, beeshop, BiG_SerGiO, buccalon, C0GuM3I0, capo, carlos rodrigues, carlosavasconcelos, cesao, Chassot, Chefe Nass, cleber, Costa, cyzko, danilosouza, dariosena, Darkluna, debal, deivisonrpg, Demerval, Diego Otani, diogeneskelsen, dmd, edlinux, fabric01, Felipe Ferreira, Felipe Marcondes, Fernando Cardia, fmakula, germanno, Gnomo, grandebaro, gutomilani, henrikesilva1, henrique.cardoso, ice, Igor_M, ijsilvestre, ismaels, ismavolk, italoraony, ixian, jacard, Jango Fett, Javanês, jaydson, jefficojava, johnnyjx, julianafsa, juliomar, Juniorvs, klausenner, Knut, kusanaguy, lafamac, lanlan, leofernandesmo, lfalcao, LForce, lkunta, Lucious, Lúcio Zanette, Maiquell, MARCIOHG, marcow, Matheus562, maximilianjx, mravel, nina.rm, nrsf, o-raposa, Obi-Wan Kenobi, oliverlessa, paint-horse, paulosantos, pemam.com.br, persiomotta, pgsnit, phsantos, r.wil, ramonrabello, rbenatti, regeriob2br, reginaldofdias, renatocoliveira, renatodondoni, rfrafa, Ricardo Chikasawa, ricdigital, roberto caceres, Robson Florentino, robsonrg, rocha, rogeriopgomes, Rogério, romualdo, SEO Crawler, srsilveira, tavares767, Telekom [Bot], Teodoro, thiago@xbrain.com.br, thiagotomais, tiasousa, Vector, VIEIRIX, vilmartr, viniciusllima, viniciusluiz, washington, wcaciano, weber, WiseNut, yeltsinlima, Yoda e 19 visitantes


Você não pode criar novos tópicos neste fórum
Você não pode responder tópicos neste fórum
Você não pode editar suas mensagens neste fórum
Você não pode excluir suas mensagens neste fórum
Você não pode enviar anexos neste fórum

Procurar por:

© 2007 - 2016 Portal Android - Comunidade de Desenvolvedores Android

Estamos no Linkedin    Siga-nos no twitter


Powered by phpBB - Hospedado por Bemobi