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?
– Paulo Rodrigues
When I call the database data with the [BD bd = new BD(getActivity());txt.setText(bd.searchConfigurations().getData());] nothing appears.
– Rodrigo Lins
This is the kind of thing you need thresh. For example, you can check whether
cursor.getString(0)
in your classDB
returns some value in console (can useLog.i()
)? If not, are you sure your method ofatualizar()
in fact is recording the data in the database?– Paulo Rodrigues
How would I put this log of information to do this analysis?
– Rodrigo Lins
With this code that I use to display the value in Textview, the Textview that has things written, some. It is always deleted.
– Rodrigo Lins
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.
– Rodrigo Lins
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 methodbuscarConfiguracoes()
, you need to give aclose()
also in the object db after using it.– Paulo Rodrigues
There was a little problem here. Now I will test your tips.
– Rodrigo Lins
This log is not displayed in debug
– Rodrigo Lins
This may be happening because the two Factions are communicating through Eventbus?
– Rodrigo Lins
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()
.– Paulo Rodrigues
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.
– Rodrigo Lins