Vinicius Biscolla
Vinicius Biscolla

Reputation: 49

AutoCompleteTextView getting the value the pacakge

okay guys i have a AutoCompleteTextView, where i'm populating from my db it's a list of customers and id, and when i extract the selected field on the AutoComplete and show in a textView or try to persist in the db it returns the name.widget.autocompletetexview{22f3r2r3"#} as the following codes show:

My AutoCompleteTextView:

            <AutoCompleteTextView
            android:id="@+id/clienteACTV"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:hint="Procure Cliente"
            android:ems="2"
            android:text="" />

My POJO Where i'm getting the data from the db, already with toString Reflections:

public class ClienteModelo implements Serializable {

private String Kunnr; // cod cliente
private String Name1; // des cliente

// private Long ClienteID; //id interno cliente

public String toString() {
    return Kunnr + "-" + Name1;
}

public String getKunnr() {
    return Kunnr;
}

public void setKunnr(String kunnr) {
    Kunnr = kunnr;
}

public String getName1() {
    return Name1;
}

public void setName1(String name1) {
    Name1 = name1;
}

}

My Helper: to get the itens of the form:

public class Nota_Helper {
public Nota notalisthelper;

public AutoCompleteTextView cliente;
public EditText N_serie;
public EditText descri_nota;


public Nota_Helper (Formulario_Nota activity) {
this.notalisthelper = new Nota();

this.cliente = (AutoCompleteTextView) activity.findViewById(R.id.clienteACTV);
this.N_serie = (EditText) activity.findViewById(R.id.ET_nserie);
this.descri_nota = (EditText) activity.findViewById(R.id.ET_descrinota);


}
public Nota pegaNotaDoFormulario() {
    notalisthelper.setCliente(cliente.getText().toString());
    notalisthelper.setN_serie(N_serie.getText().toString());
    notalisthelper.setDescri_nota(descri_nota.getText().toString());

    return notalisthelper;

}

}

My Form Activity where i call the AutoComplete, shows what is in it, and try to persist:

    Dados_Mestres_DAO dao = new Dados_Mestres_DAO(this);
    clientes = dao.getListaClientes();
    dao.close();

    AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.clienteACTV);
    actv.setThreshold(3);
    ArrayAdapter<ClienteModelo> adapter = new ArrayAdapter<ClienteModelo>(Formulario_Nota.this, android.R.layout.select_dialog_item, clientes);
    actv.setAdapter(adapter);// setting the adapter data into the
    actv.setTextColor(Color.BLACK);

Button botao_add = (Button) findViewById(R.id.btn_addnota); //to show
    botao_add.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
        String autocliente = actv.getText().toString();
        TextView clientview = (TextView) findViewById(R.id.clienteview);
                    clientview.setText("Cliente: " + actv);
Button botao_salvar = (Button) findViewById(R.id.btn_salvar); //to persist
    botao_salvar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.clienteACTV);
           Nota notalist = nota_helper.pegaNotaDoFormulario();
                Stara_DB NotaDao = new Stara_DB(Formulario_Nota.this);

                notas = NotaDao.getListaNota();
                NotaDao.insereNota(notalist);

                Toast.makeText(Formulario_Nota.this, "Dados Salvos com sucesso", Toast.LENGTH_LONG).show();
                NotaDao.close();

                Intent continuar = new Intent(Formulario_Nota.this, Formulario_ItemNota.class);
                finish();
                startActivity(continuar);
                return;

what i am missing ??

Upvotes: 0

Views: 421

Answers (1)

laalto
laalto

Reputation: 152827

Override toString() in your ClienteModelo class to produce a string representation other than the default provided by Object.toString().

Upvotes: 1

Related Questions