Assign an element [name] of the database that is in a list to an Edittext

Asked

Viewed 27 times

0

nome = (EditText) findViewById(R.id.edt_nomecli);

listaclientes.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {                   
        Integer cod = i;
        Cursor cursor = banco.rawQuery("SELECT nome FROM clientes WHERE id_cli = '"+cod+"' ",null);
        if(cursor!=null)
        {  
            int cnome=cursor.getColumnIndex("nome");
            nome.setText(cursor.getString(cnome), TextView.BufferType.EDITABLE);
        }  
    }  
});

THE ERROR IS AT EXECUTION TIME.

  • Are you adding final before and declare a variable nome? Ex: final String nome = (EditText) findViewById(R.id.edt_nomecli);

  • What’s the mistake ?

  • I suggest you search the bank when you start activity and save in a ArrayList, the way he is doing he searches that list from the bank whenever the user clicks on ListView having a performance reduction

1 answer

0

I managed to solve...

nome = (EditText) findViewById(R.id.edt_nomecli);

listaclientes.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {                   
    final Integer j = i;
      String n = adapternome.getItem(j).toString();
        try {
            Cursor cursor = banco.rawQuery("SELECT * FROM clientes WHERE nome = '" + n +"'", null);
            int colunaN = cursor2.getColumnIndex("nome");
            cursor.moveToFirst();
            while (cursor != null)
           {
             nome.setText(cursor.getString(colunaN), TextView.BufferType.EDITABLE);
             abas.setCurrentTab(1);
             cursor.moveToNext();
            }
       }catch (Exception E ){E.printStackTrace();}
    }  
});

Browser other questions tagged

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