使用TextWatcher更新ListView中的EditText

时间:2014-05-17 13:35:26

标签: java android android-listview textwatcher

首先,我要编写一些代码来尝试一些代码:

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.unit, parent, false);
        final TextView unitName = (TextView) rowView.findViewById(R.id.unit_name);
        final EditText unitValue = (EditText) rowView.findViewById(R.id.unit_value);

        if(units.get(position).getView() == 1) {
            unitName.setText(units.get(position).getUnitName());
            unitValue.setText("0.00");
        } else {
            unitName.setVisibility(View.GONE);
            unitValue.setVisibility(View.GONE);
        }

        unitValue.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                //nothing here
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                HashMap<String, Double> conversionFactors = new HashMap<String, Double>();
                //CONVERTER CLASS
                Converter converter = new Converter(type, unitName.getText().toString(), unitValue.getText().toString());
                //CONVERT METHOD
                conversionFactors = converter.convert();
                //UPDATE ALL OF THE UNITVALUES IN THEIR CURRENT ORDER
            }

            @Override
            public void afterTextChanged(Editable s) {
                //nothing here
            }
        });

        return rowView;
    }

我有一个HashMap,其中键是布局中的TextView个对象,所以我将通过它们并使用相应的值更新相应的EditText个对象。 HashMap

这将在onTextChanged方法中发生,但问题在于我的理解。既然我已经实例化了视图,那么我可以通过迭代遍历所有EditText个对象并更新它们吗?或者我只是更新我的ArrayAdapter?不确定下一步该去哪里...真的很感激一些见解。

0 个答案:

没有答案