AutoCompleteTextView获取包的值

时间:2014-12-09 11:20:23

标签: android sqlite dao autocompletetextview

好吧,伙计们我有一个AutoCompleteTextView,我在我的数据库中填充它是一个客户和id的列表,当我在AutoComplete上提取所选字段并在textView中显示或尝试在数据库中保留时它返回name.widget.autocompletetexview {22f3r2r3“#}如以下代码所示:

我的自动完成文本视图:

            <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="" />

我的POJO我从db获取数据,已经使用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;
}

}

我的助手:获得表格的含义:

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;

}

}

我调用自动完成功能的表单活动,显示其中的内容,并尝试保留:

    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;

我错过了什么?

1 个答案:

答案 0 :(得分:1)

覆盖toString()类中的ClienteModelo以生成除Object.toString()提供的默认值之外的字符串表示。