1
How to take the data from a table and present them each in one EditText
?
I’m developing on Android. Here I do the List
of the data I need:
public List<ConfiguracoesSistema> listarConfiguracoes() {
// List que recebe os dados que são percorridos no while
List<Configuracao> listaConfiguracoes = new ArrayList<Configuracao>();
// Variável para utilizar a query no Cursor
String sql = "select * from teste";
// Objeto que recebe os registros do Banco de Dados
Cursor cursor = getReadableDatabase().rawQuery(sql, null);
try {
// Percorre todos os registros do cursor
while (cursor.moveToNext()) {
Configuracao configuracoes = new Configuracao();
// Carrega os atributos do Banco de Dados
configuracoes.setCodigoSistema(cursor.getLong(0));
configuracoes.setNomeEmpresa(cursor.getString(1));
configuracoes.setEnderecoEmpresa(cursor.getString(2));
// Adiciona os pedidos na Lista para ser apresentado
listaConfiguracoes.add(configuracoes);
}
} catch (Exception e) {
Log.i(TAG, e.getMessage());
} finally {
// Garante o fechamento do Banco de Dados
cursor.close();
}
return listarConfiguracoes();
}
And I got the class Activity
public class ConfiguracoesSistema extends Activity implements
OnItemClickListener {
private EditText codigoSistema;
private EditText razaoSocial;
private EditText enderecoEmpresa;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tela_configuracoes);
razaoSocial = (EditText) findViewById(R.id.edtRazaoSocial);
enderecoEmpresa = (EditText) findViewById(R.id.edtEndereco);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
}
How to get the Sqlite database data from that List
and pass it on to the EditText
each field?
Which language are you using? could give more details or an excerpt of code already produced.
– rray
you can edit your question and add this code, to format the code use the button
{ }
. Take advantage and see how the site works with these links about and help– rray
I edited the question.
– user2362558
Newbie on the site. I hadn’t noticed the buttons.
– user2362558
I don’t understand what your doubt is, it seems you’ve done it all, haven’t done it?
– Math
No. I’m not getting the database data presented in Edittext.
– user2362558
where you want to do it, inside the
onItemClick
?– Math
So. The idea is this. Take the saved data from the settings table and present them in Edittext that are fixed. When the Adm user wants to change it will have a button. I just really want to take each field of the table and present it in an individual Edittext.
– user2362558
@user2362558, instead of clarifying here in the comments, [Edit]and the question to add new information. Then, just let us know
"@fulano, editei a pergunta"
– brasofilo