我的自动完成文本视图:
<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;
我错过了什么?
答案 0 :(得分:1)
覆盖toString()
类中的ClienteModelo
以生成除Object.toString()
提供的默认值之外的字符串表示。