0

我的活动中有 Gridview。我的 GridView 的数据适配器:

private class EfficientAdapter extends BaseAdapter {
        ...
        public View getView(int position, View convertView, ViewGroup parent) {
            final ViewHolder holder;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.item3, null);
                holder = new ViewHolder();
                holder.Attitude_Value = (EditText) convertView.findViewById(R.id.editText1);
                holder.Attitude_Value.addTextChangedListener(new TextWatcher()
                    {
                        public void afterTextChanged(Editable edt) 
                        {attitude_values.set(holder.ref, edt.toString());}

            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3){}
            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}});
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.ref=position;
            holder.Attitude_Value.setText(attitude_values.get(position));
            return convertView;
        }
   ...

如何在开始输入之前清除网格视图中的编辑框,当我关注它时?

4

2 回答 2

0

您是否尝试过这样我不太确定更改您的 XML Edittext

android:hint="Something"

试试这个链接示例

et.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        et.setCompoundDrawables(null, null, et.getText().toString().equals("") ? null : x, null);
    }

    @Override
    public void afterTextChanged(Editable arg0) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
});
于 2013-01-25T06:30:11.710 回答
0
String value = "anyValue";

final EditText et = (EditText) findViewById(R.id.edtText);
et.setText(value);
et.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        if (event.getAction() != MotionEvent.ACTION_UP) {
            et.setText(et.getText().toString.trim());
            return false;
        }

        if (event.getAction() != MotionEvent.ACTION_DOWN) {
            value = et.getText().toString.trim();
            et.setText("");
            return true;
        }
        return false;
    }
});

et.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void afterTextChanged(Editable arg0) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
});
于 2013-01-25T06:53:36.587 回答