我知道这个问题之前被问过很多次,并且遵循了他们,我在很大程度上达到了目标,只剩下一个问题。我能够通过添加文本观察器并使用哈希图来存储值来解决重复问题,但剩下的问题是当我滚动回它时,原始编辑文本的值也消失了。我的意思是,如果我先输入一些东西,比如说先EditText
然后向下滚动,该值不会在任何地方重复,但我键入的EditText
值也消失了。这是我的代码。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.list_planmanobra_row, parent, false);
holder.periodo_zafra = (TextView) convertView.findViewById(R.id.periodo_zafra);
holder.CODIGO_FINCA = (TextView) convertView.findViewById(R.id.CODIGO_FINCA);
//holder.NOMBRE_FINCA = (TextView) convertView.findViewById(R.id.NOMBRE_FINCA);
holder.MES = (TextView) convertView.findViewById(R.id.MES);
holder.CLAVE = (TextView) convertView.findViewById(R.id.CLAVE);
holder.NOMBRE_CLAVE = (TextView) convertView.findViewById(R.id.NOMBRE_CLAVE);
holder.CODIGO_ESTANDAR = (TextView) convertView.findViewById(R.id.CODIGO_ESTANDAR);
holder.NOMBRE_ESTANDAR_MO = (TextView) convertView.findViewById(R.id.NOMBRE_ESTANDAR_MO);
holder.CANTIDAD_ESTANDAR = (TextView) convertView.findViewById(R.id.CANTIDAD_ESTANDAR);
holder.VALOR_UNITARIO = (TextView) convertView.findViewById(R.id.VALOR_UNITARIO);
holder.VALOR_TOTAL = (TextView) convertView.findViewById(R.id.VALOR_TOTAL);
holder.EJECUTA = (TextView) convertView.findViewById(R.id.EJECUTA);
holder.btn_submit= (Button) convertView.findViewById(R.id.btn_submit);
holder.btn_submit.setText("Enviar");
holder.Cantidad= (EditText) convertView.findViewById(R.id.et_cantidad);
holder.Cantidad_empleados= (EditText) convertView.findViewById(R.id.Cantidad_empleados);
holder.checkbox= (CheckBox) convertView.findViewById(R.id.checkbox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.periodo_zafra.setText(planmanobraBeanArrayList.get(position).getPERIODO_ZAFRA());
holder.CODIGO_FINCA.setText(planmanobraBeanArrayList.get(position).getCODIGO_FINCA());
// holder.NOMBRE_FINCA.setText(planiBeanArrayList.get(position).getNOMBRE_FINCA());
holder.MES.setText(planmanobraBeanArrayList.get(position).getMES());
holder.CLAVE.setText(planmanobraBeanArrayList.get(position).getCLAVE());
holder.NOMBRE_CLAVE.setText(planmanobraBeanArrayList.get(position).getNOMBRE_CLAVE());
holder.CODIGO_ESTANDAR.setText(planmanobraBeanArrayList.get(position).getCODIGO_ESTANDAR());
holder.NOMBRE_ESTANDAR_MO.setText(planmanobraBeanArrayList.get(position).getNOMBRE_ESTANDAR_MO());
holder.CANTIDAD_ESTANDAR.setText(planmanobraBeanArrayList.get(position).getCANTIDAD_ESTANDAR());
holder.VALOR_UNITARIO.setText(planmanobraBeanArrayList.get(position).getVALOR_UNITARIO());
holder.VALOR_TOTAL.setText(planmanobraBeanArrayList.get(position).getVALOR_TOTAL());
holder.EJECUTA.setText(planmanobraBeanArrayList.get(position).getEJECUTA());
holder.Cantidad.setText(editTextList.get(position));
holder.Cantidad.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
editTextList.put(position,charSequence.toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
holder.btn_submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return convertView;
}
坎蒂达是编辑文本
最后,
我使用焦点更改侦听器让它工作,并向现有数组列表再添加一个参数。使用另一个列表或哈希图对我不起作用。因此,按照 Yazan 的建议,我将其添加到我的数组列表中,现在正在工作。这是我现在拥有的代码
holder.Cantidad.setText(planmanobraBeanArrayList.get(position).getEditext());
final ViewHolder finalHolder = holder;
holder.Cantidad.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus)
{
if (!finalHolder.Cantidad.getText().toString().equals(""))
{
planmanobraBeanArrayList.get(position).setEditext(finalHolder.Cantidad.getText().toString());
}else {
planmanobraBeanArrayList.get(position).setEditext("");
}
}
}
});
感谢大家的帮助