Android EditText值无法向上/向下滚动ListView

时间:2014-01-14 12:44:46

标签: android listview android-edittext default-value

这是我的适配器

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;
    LayoutInflater inflater = activity.getLayoutInflater();
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.item, null);
        holder = new ViewHolder();

        holder.txtFirst = (TextView) convertView.findViewById(R.id.textView1);
        holder.txtSecond = (TextView) convertView.findViewById(R.id.textView2);
        holder.txtid = (TextView) convertView.findViewById(R.id.textView3id);
        holder.txtThird = (EditText) convertView.findViewById(R.id.ItemCaption);
        holder.btn1 = (ImageButton) convertView.findViewById(R.id.button1);
        holder.btn2 = (ImageButton) convertView.findViewById(R.id.button2);


    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (!holder.txtThird.getText().toString().equals("")) {
                Sayac = Integer.valueOf(holder.txtThird.getText().toString());
            } else {
                Sayac = 0;
            }
            Sayac++;
            holder.txtThird.setText(String.valueOf(Sayac));
        }
    });
    holder.btn2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!holder.txtThird.getText().toString().equals("")) {
                Sayac = Integer.valueOf(holder.txtThird.getText().toString());
            }else{
                Sayac = 0;
            }
            if (Sayac > 0) {
                Sayac--;
                holder.txtThird.setText(String.valueOf(Sayac)); 
            }
        }
    });



    @SuppressWarnings("rawtypes")
    HashMap map = list.get(position);
    String first = (String) map.get(Seri);
    String second = (String) map.get(Sira);
    String id = (String) map.get(Tarih);

    holder.txtFirst.setText(first);
    holder.txtSecond.setText(second);
    holder.txtid.setText(id);
    holder.txtThird.setText("0");
    convertView.setTag(holder);
    return convertView;
}

这里我在数量不等于'0'时插入数据库表:

 for (int i = 0; i < lv.getAdapter().getCount()-1; i++) {
            HashMap<?, ?> result = (HashMap<?, ?>)lv.getItemAtPosition(i);       
            View vListSortOrder;
            vListSortOrder=lv.getChildAt(i);    
            TextView Sort_DeliveryOrder=(TextView)vListSortOrder.findViewById(R.id.ItemCaption);
            String Fiyats = String.valueOf(result.get(Sira).toString().trim().replace(",", "."));
            String iskDizi[] = new String[3];
            if (Integer.valueOf(Sort_DeliveryOrder.getText().toString()) != 0) {
                //Process
            }

但我有一个问题。 ListView向上/向下滚动量值在更改时获取默认值。我需要ListView向上/向下滚动量值不要更改而不是设置默认值。

1 个答案:

答案 0 :(得分:0)

是滚动视图时是循环或创建新视图,在那里调用getView()方法

holder.txtThird.setText("0");

而是从数据库中保存数据并设置文本

int value = database.getValue();
holder.txtThird.setText(String.valueOf(value));

看看是否有效:)