有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用TextWatcher更新ListView中的EditText

首先,我写了一些代码来尝试一下:

@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对象,所以我将遍历它们并使用HashMap中的相应值更新它们相应的EditText对象

它将在onTextChanged方法中发生,但问题是我的理解。既然我已经实例化了视图,有没有一种方法可以迭代所有EditText对象并更新它们?或者我应该只更新我的ArrayAdapter?不确定下一步该去哪里。。。我真的很想了解一些情况


共 (0) 个答案