我有一个自定义 ListView,其中包含一些 TextView、EditText 和一个代表购物清单项目的复选框。当我在值Edittext中键入值时,我会检查复选框,敬酒向我显示了值乘以其各自数量的总和,当所有项目的所有复选框都被检查时,对话框向我显示了购物列表的总价值。我的问题是,当我输入值后隐藏数字键盘时,复选框失去了选中状态。可能是什么问题呢?
这是我的 getView 方法的部分代码:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
SharedPreferences sharedPrefs = contexto.getSharedPreferences("sharedPrefs", Context.MODE_PRIVATE);
if (convertView == null) {
LayoutInflater inflater = contexto.getLayoutInflater();
convertView = inflater.inflate(R.layout.items_layout, null);
holder = new ViewHolder();
holder.texto = (TextView) convertView.findViewById(R.id.txtDescricao);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.chkProduto);
holder.edtValor = (EditText) convertView.findViewById(R.id.txtValor);
holder.edtQtde = (EditText) convertView.findViewById(R.id.txtQuantidade);
holder.btnMenos = (Button) convertView.findViewById(R.id.btnMenos);
holder.btnMais = (Button) convertView.findViewById(R.id.btnMais);
//holder.btnExcluir = (ImageButton) convertView.findViewById(R.id.btnExcluir);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
editor = sharedPrefs.edit();
holder.posicao = position;
holder.texto.setText(getItem(position).getTexto());
if(getItem(position).getValor() > 0)
holder.edtValor.setText(Double.toString(getItem(position).getValor()));
else
holder.edtValor.setText("");
holder.edtValor.setTag(new LinhaItemTag(getItem(position), position));
holder.edtValor.addTextChangedListener(new TextWatcherValor(holder));
if(quantidades[position] > 0)
holder.edtQtde.setText(Integer.toString(quantidades[position]));
else
holder.edtQtde.setText("");
holder.edtQtde.setTag(new LinhaItemTag(getItem(position), position));
holder.edtQtde.addTextChangedListener(new TextWatcherQuantidade(holder));
holder.btnMenos.setTag(new LinhaItemTag(getItem(position), position));
holder.btnMais.setTag(new LinhaItemTag(getItem(position), position));
//holder.btnExcluir.setTag(new LinhaItemTag(getItem(position), position));
holder.checkbox.setOnCheckedChangeListener(null);
//holder.checkbox.setChecked(getItem(position).Selecionado());
getItem(position).setSelecionado(sharedPrefs.getBoolean("CheckValue"+position, false));
holder.checkbox.setChecked(getItem(position).Selecionado());
holder.checkbox.setTag(new LinhaItemTag(getItem(position), position));
holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
LinhaItemTag elemento = (LinhaItemTag) buttonView.getTag();
elemento.item.setSelecionado(isChecked);
editor.putBoolean("CheckValue"+position, isChecked);
editor.commit();
if (isChecked) {
pegos[elemento.position] = true;
} else {
pegos[elemento.position] = false;
}
String vlrTotal = calculaTotal();
boolean checados = true;
for (int i = 0; i < lista.size(); i++) {
if (!pegos[i]) {
checados = false;
break;
}
}
if (checados) {
mostraDlgFinaliza();
}
else if(getItem(elemento.position).Selecionado())
{
Toast.makeText(contexto, "R$ " + vlrTotal, Toast.LENGTH_LONG).show();
}
}
});
//Other piece of code
return convertView;
}