我ListView
用 someTextView
和a 编写了 a EditText
。这个有一个TextWatcher
which inafterTextChange()
方法将一个实例添加到一个 sigleton 类。一切都很好,但是当我滚动ListView
并修改 an 的值时EditText
,ListView
会重新加载并在顶部返回滚动条。这是正常的反馈还是我可以控制这种行为?
文本观察者的一部分
@Override
public void afterTextChanged(Editable s) {
if(!s.toString().isEmpty()){
if (Integer.parseInt(s.toString())!=0){
HashMap<Products, Integer> into=new HashMap<Products,Integer>();
Products pr = new Products();
into = cart.getProdotti();
pr.set_id(Integer.parseInt(pro.get("id").toString()));
pr.setPrezzo(Double.parseDouble(pro.get("prezzo").toString()));
pr.setNome(pro.get("nome").toString());
boolean flag = false;
if(!into.isEmpty()){
Iterator<Products> iter = into.keySet().iterator();
while(iter.hasNext()){
if(pr.get_id()==iter.next().get_id()){
into.put(pr, Integer.parseInt(s.toString()));
cart.setProdotti(into);
flag = true;
}
}
if(flag==false){
into.put(pr, Integer.parseInt(s.toString()));
cart.setProdotti(into);
}
}else{
into.put(pr, Integer.parseInt(s.toString()));
cart.setProdotti(into);
}
}
}
}
GETVIEW 适配器
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.product_row, null);
TextView nome = (TextView)vi.findViewById(R.id.nomeProdotto); // title
TextView descrizione = (TextView)vi.findViewById(R.id.descrizioneProdotto); // artist name
TextView prezzo = (TextView)vi.findViewById(R.id.prezzoProdotto); // duration
//ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
final EditText quantity = (EditText)vi.findViewById(R.id.quantity);
product = products.get(position);
nome.setText(product.get("nome"));
descrizione.setText(product.get("descrizione"));
prezzo.setText("€"+product.get("prezzo"));
quantity.setText("0");
quantity.addTextChangedListener(new CustomTextWatcher(products.get(position)));
//imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
return vi;
}