Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ListView中的EditText滚动问题未得到解决_Android - Fatal编程技术网

Android ListView中的EditText滚动问题未得到解决

Android ListView中的EditText滚动问题未得到解决,android,Android,我有一个包含四个EditText的ListView。当我在这些字段中输入一些文本并滚动时,数据丢失了。我试过很多例子,但都不管用。请帮忙 public NewOrderTotalCountAdapter(Context context, int resource, List<Object> objList) { super(context, resource, objList); this.context = context; this.res

我有一个包含四个EditText的ListView。当我在这些字段中输入一些文本并滚动时,数据丢失了。我试过很多例子,但都不管用。请帮忙

public NewOrderTotalCountAdapter(Context context, int resource,
        List<Object> objList) {
    super(context, resource, objList);
    this.context = context;
    this.resourceId = resource;
    this.objArrayList = objList;
    Log.i("Size============", String.valueOf(objList.size()));
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View totalView = convertView;
    TotalCountHolder totalCountHolder;
    if (totalView == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        totalView = inflater.inflate(resourceId, parent, false);

        totalCountHolder = new TotalCountHolder();
        totalCountHolder.productsNameView = (EditText) totalView
                .findViewById(R.id.productName);
        totalCountHolder.productQuantityView = (EditText) totalView
                .findViewById(R.id.quantity);
        totalCountHolder.productUnitPriceView = (EditText) totalView
                .findViewById(R.id.unitPrice);
        totalCountHolder.productTotalPriceView = (EditText) totalView
                .findViewById(R.id.totalPrice);
        totalCountHolder.btnDel = (Button) totalView
                .findViewById(R.id.btnDel);
         totalCountHolder.productsNameView
         .addTextChangedListener(new TextWatchers(
         totalCountHolder.productsNameView, position));
         totalCountHolder.productQuantityView
         .addTextChangedListener(new TextWatchers(
         totalCountHolder.productQuantityView, position));
         totalCountHolder.productUnitPriceView
         .addTextChangedListener(new TextWatchers(
         totalCountHolder.productUnitPriceView, position));
         totalCountHolder.productTotalPriceView
         .addTextChangedListener(new TextWatchers(
         totalCountHolder.productTotalPriceView, position));

        totalCountHolder.btnDel.setTag(position);
        totalCountHolder.btnDel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Integer index = (Integer) v.getTag();

                objArrayList.remove(index.intValue());
                notifyDataSetChanged();
            }
        });
        totalView.setTag(totalCountHolder);

    } else {
        totalCountHolder = (TotalCountHolder) totalView.getTag();
    }
    try {

        if (objArrayList != null) {
            if (position < objArrayList.size()) {
                ProductsEntity productEntity = (ProductsEntity) objArrayList
                        .get(position);
                String productName = productEntity.getProcdut_name();
                String quantity = productEntity.getQuantity();
                String unitPrice = productEntity.getUnit_price();
                String total_price = productEntity.getTotal_price();
                totalCountHolder.productsNameView.setText(productName);
                totalCountHolder.productQuantityView.setText(quantity);
                totalCountHolder.productUnitPriceView.setText(unitPrice);
                totalCountHolder.productTotalPriceView.setText(total_price);
                totalCountHolder.btnDel.setVisibility(View.VISIBLE);

            } else {

            totalCountHolder.productsNameView.setText("");
            totalCountHolder.productQuantityView.setText("");
            totalCountHolder.productUnitPriceView.setText("");

            totalCountHolder.productTotalPriceView.setText("");
                totalCountHolder.btnDel.setVisibility(View.GONE);
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return totalView;
}

@Override
public int getCount() {
    int i = objArrayList.size();
    int j = i + 2;
    return objArrayList != null ? j : 0;

}

private class TotalCountHolder {
    EditText productsNameView;
    EditText productQuantityView;
    EditText productUnitPriceView;
    EditText productTotalPriceView;
    Button btnDel;
}

class TextWatchers implements TextWatcher {
    View view;
    int position;

    TextWatchers(View view, int position) {
        this.view = view;
        this.position = position;

    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before,
            int count) {

    }

    @Override
    public void afterTextChanged(Editable s) {

        EditText et = (EditText) view;

        if (view.getId() == R.id.productName) {
            ProductsEntity productEntity = (ProductsEntity) objArrayList
                    .get(position);
            String name = et.getText().toString().trim();
            productEntity.setProcdut_name(name);
            //objArrayList.set(position, productEntity);
            Log.i("Name====", name);
            Log.i("Product Entity====", productEntity.toString());
            return;

        }
        if (view.getId() == R.id.quantity) {
            ProductsEntity productEntity = (ProductsEntity) objArrayList
                    .get(position);
            String name = et.getText().toString().trim();
            productEntity.setQuantity(name);
            //objArrayList.set(position, productEntity);
            Log.i("Name====", name);
            Log.i("Product Entity====", productEntity.toString());
            return;

        }
        if (view.getId() == R.id.unitPrice) {
            ProductsEntity productEntity = (ProductsEntity) objArrayList
                    .get(position);
            String name = et.getText().toString().trim();
            productEntity.setUnit_price(name);
            //objArrayList.set(position, productEntity);
            Log.i("Name====", name);
            Log.i("Product Entity====", productEntity.toString());
            return;

        }
        if (view.getId() == R.id.totalPrice) {
            ProductsEntity productEntity = (ProductsEntity) objArrayList
                    .get(position);
            String name = et.getText().toString().trim();
            productEntity.setTotal_price(name);
            //objArrayList.set(position, productEntity);
            Log.i("Name====", name);
            Log.i("Product Entity====", productEntity.toString());
            return;

        }

    }

}
公共NewOrderTotalCountAdapter(上下文、int资源、, 列表对象列表){ 超级(上下文、资源、对象列表); this.context=上下文; this.resourceId=资源; this.objArrayList=objList; Log.i(“大小==============”,String.valueOf(objList.Size()); } @凌驾 公共视图getView(int位置、视图转换视图、视图组父视图){ 视图totalView=convertView; TotalCountHolder TotalCountHolder; 如果(totalView==null){ LayoutInflater充气器=((活动)上下文)。getLayoutInflater(); totalView=充气机。充气(resourceId,父项,false); totalCountHolder=新的totalCountHolder(); totalCountHolder.productsNameView=(编辑文本)totalView .findViewById(R.id.productName); totalCountHolder.productQuantityView=(编辑文本)totalView .findViewById(R.id.数量); totalCountHolder.productUnitPriceView=(编辑文本)totalView .findViewById(R.id.单价); totalCountHolder.productTotalPriceView=(编辑文本)totalView .findViewById(R.id.总价); totalCountHolder.btnDel=(按钮)totalView .findviewbyd(R.id.btnDel); totalCountHolder.productsNameView .addTextChangedListener(新的TextWatchers( totalCountHolder.productsNameView,position)); totalCountHolder.productQuantityView .addTextChangedListener(新的TextWatchers( totalCountHolder.productQuantityView,position)); totalCountHolder.productUnitPriceView .addTextChangedListener(新的TextWatchers( totalCountHolder.productUnitPriceView,position)); totalCountHolder.productTotalPriceView .addTextChangedListener(新的TextWatchers( totalCountHolder.productTotalPriceView,位置); totalCountHolder.btnDel.setTag(位置); totalCountHolder.btnDel.setOnClickListener(新的OnClickListener(){ @凌驾 公共void onClick(视图v){ //TODO自动生成的方法存根 整数索引=(整数)v.getTag(); 移除(index.intValue()); notifyDataSetChanged(); } }); totalView.setTag(totalCountHolder); }否则{ totalCountHolder=(totalCountHolder)totalView.getTag(); } 试一试{ if(objArrayList!=null){ if(位置