problems when passing data to Edittext Android

Asked

Viewed 243 times

2

I’m having trouble loading data from an sqlite table and sending this data to Edittext, which I may be doing wrong, when I open the screen returns this message in the log Cat

11-03 06:43:30.721 14420-14420/routerbox.com.br.centraisdoassinante I/Choreographer: Skipped 52 frames!  The application may be doing too much work on its main thread.



package routerbox.com.br.centraisdoassinante;

import android.app.ProgressDialog;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;

import java.sql.SQLException;
import java.util.List;

import routerbox.com.br.centraisdoassinante.routerbox.com.br.centraisdoassinante.Dao.PessoaDao;
import routerbox.com.br.centraisdoassinante.routerbox.com.br.centraisdoassinante.models.Pessoa;

/**
 * Created by rodrigo on 01/11/16.
 */

public class DadosCadastrais extends AppCompatActivity {
     private EditText edtNome ;
     private EditText edtCnpjCpf ;
     private EditText edtRgIe ;
     private EditText edtCep;
     private EditText edtUf ;
     private EditText edtCidade;
     private EditText edtBairro ;
     private EditText edtEndereco;
     private EditText edtnumero ;
     private EditText edtComplemento;
     private EditText edtFoneComercial;
     private EditText edtFoneResidencial;
     private EditText edtFoneCelular;
     private  EditText edtEmail ;
     private PessoaDao pessoaDao;
     private Pessoa pessoa;
     ProgressDialog dialog;

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

    public void carregarDados() throws SQLException {
            pessoa = pessoaDao.queryForId(1);
            edtNome= (EditText)findViewById(R.id.edtNome);
            edtNome.setText(pessoa.getNome());
    }

}
  • But is the APP crashing? This message does not seem to be caused by your editText

  • maybe the query is too heavy and by the fact that it runs in the UI Thread should be slow and locking.

  • @Mr_anderson, I’d better load this query in another class?

  • So...It’s just a theory. I’m not sure what it might be, because this Choreografer error has a connection with the visual part, but as the query is called before invoking edt, then it might be heavy. There may also be many other errors. Here you can help: http://stackoverflow.com/questions/11266535/meaning-of-choreographer-messages-in-logcat

  • If Voce is going to load the data in another class, you will have to use an Asynctask, for example. From what I saw, I don’t think it should be a problem in the query, because Voce uses sqlite...

  • @Mr_anderson, I’m using sqlite, so will I try with Asynctask? but a question the way I’m doing is right to upload the data to Edittext?

  • as it is loading few data from sqlite, no need to async. I thought it was a query in external database. My error... The data is being loaded right...I would only put each functionality separately. a place only for cast and another just to load and value.

  • @Mr_anderson, I got it. Thanks

Show 3 more comments

1 answer

1


I solved the problem I wasn’t passing the database connection, so when it was instantiated it created a new reference.

protected void onCreate(Bundle savedInstanceState)  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dados_cadastrais);
    databaseHelper = new DatabaseHelper(DadosCadastrais.this);

    new Thread(new Runnable() {
        @Override
        public void run() {

            try {
                pessoaDao = new PessoaDao(databaseHelper.getConnectionSource());
                pessoa= pessoaDao.queryForId(1);
                edtNome= (EditText) findViewById(R.id.edtNome);
                edtNome.setText(pessoa.getNome());

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


        }
    }).start();




}

Browser other questions tagged

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