2

我有一个 ArrayAdapter,我正在使用 TextWatcher 在一些 TextView 中进行控制更改,但是我遇到了问题。我不知道如何在更改后选择可编辑视图。我试图添加一个 OnClickListener 并获得一些利润,但为了一切顺利,我首先需要点击 View 和 TextView 时

ViewHolder holder;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {     

        if (convertView == null) {
            LayoutInflater inflater = 
                    (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.item_row, null);

            holder = new ViewHolder();
            holder.value = (EditText) convertView.findViewById(R.id.value);
            holder.item = (TextView) convertView.findViewById(R.id.item);
            holder.relust = (TextView) convertView.findViewById(R.id.result);

            convertView.setOnClickListener(this);       


            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.item.setText(items.get(position) + "");
        holder.position = position;
        return convertView;
    }

    @Override
    public void afterTextChanged(Editable text) {
        if (text.length() != 0) {
            Double value = Double.valueOf(text.toString());
            Double result = value * 2;
            holder.relust.setText("= " + result + " sm");
        }
    }

    @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 onClick(View v) {
        holder = (ViewHolder) v.getTag();
        holder.value.addTextChangedListener(this);
    }
4

0 回答 0