ArrayAdapter中的TextWatch

时间:2012-12-06 15:49:14

标签: android

我有一个ArrayAdapter,我在一些TextView中使用TextWatcher来控制更改,但是我遇到了问题。我不知道如何在更改后选择可编辑视图。我试图添加一个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);
    }

0 个答案:

没有答案