Problem while passing database data to Textview android

Asked

Viewed 183 times

0

I am unable to display database data to Textview.

BD

public MessageEB buscarConfiguracoes() {

    String[] colunas = new String[]{"data"};

    Cursor cursor = bd.query("dados", colunas, null, null, null, null, null);

    MessageEB messageEB = new MessageEB();

    if (cursor.moveToNext()) {
        messageEB.setData(cursor.getString(0));
    }

    cursor.close();

    return messageEB;
}

Fragment Enviar

@Override
    public void onClick(View v) {
        Log.i("LOG", "FragmentEnviar.this.onClick()");

        MessageEB m = new MessageEB();
        m.setClassTester(FragmentExibir.class+"");
        m.setData(editar.getText().toString());

        EventBus.getDefault().post(m);

        dados.setData(editar.getText().toString());
        BD bd = new BD(getActivity());
        bd.atualizar(dados);

        Toast.makeText(getActivity(), "Data alterada com sucesso! " + dados.getData(), Toast.LENGTH_SHORT).show();
    }

Fragment View

 public View onCreateView(LayoutInflater inflater,  ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_exibir, container, false);

        EventBus.getDefault().register(FragmentExibir.this);


    txt = (TextView) view.findViewById(R.id.campoData2);


    BD bd = new BD(getActivity());
    txt.setText(bd.buscarConfiguracoes().getData());

    return view;
}

Data is the name of the database table. When I call the bank dice, it is not displayed.

  • What exactly isn’t working? Can’t you get it from the bank? If you do, what happens after you’re not meeting your need?

  • When I call the database data with the [BD bd = new BD(getActivity());txt.setText(bd.searchConfigurations().getData());] nothing appears.

  • This is the kind of thing you need thresh. For example, you can check whether cursor.getString(0) in your class DB returns some value in console (can use Log.i())? If not, are you sure your method of atualizar() in fact is recording the data in the database?

  • How would I put this log of information to do this analysis?

  • With this code that I use to display the value in Textview, the Textview that has things written, some. It is always deleted.

  • This error appears: A Sqliteconnection Object for database was leaked! Please fix your application to end transactions in Progress properly and to close the database when it is no longer needed.

  • Utilize Log.i("a", cursor.getString(0)) or if it’s easier, use the functions of debug from the IDE itself. This is just to see if there really is the expected value in the database. In your method buscarConfiguracoes(), you need to give a close() also in the object db after using it.

  • There was a little problem here. Now I will test your tips.

  • This log is not displayed in debug

  • This may be happening because the two Factions are communicating through Eventbus?

  • I don’t know what that Eventbus does, I believe it has no relation. But if it is not displaying, maybe it is not really saving. Then it is necessary to validate this in your method atualizar().

  • Yes, I believe that this may be the problem. I need to analyze the problem, but I’ve seen so much of this code, I don’t know where the error might be. Eventbus makes communication between Factions.

Show 7 more comments
No answers

Browser other questions tagged

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