0

我有一个预填充值“请评论...”的编辑文本字段,现在我想在用户触摸此字段时删除此内容。在文档中,我看到可以将 onTouchEvent 添加到 edittext 字段。但它不起作用,因为编译器错误发生在

The method onTouchEvent(MotionEvent) in the type TextView is not applicable for the arguments (new View.OnTouchListener(){})

我的代码是:

        comment.onTouchEvent(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (comment.getText().equals( R.string.comment_content )){
                    comment.setText( "" );
                    return true;
                }
                return false;

            }});

谢谢

4

2 回答 2

1

不要手动执行此操作。Android 已经提供了这个功能:“提示文本”

于 2012-12-18T18:22:35.057 回答
0
MyEditor.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
    int inType = MyEditor.getInputType(); // backup the input type
    MyEditor.setInputType(InputType.TYPE_NULL); // disable soft input
    MyEditor.onTouchEvent(event); // call native handler
    MyEditor.setInputType(inType); // restore input type
    return true; // consume touch even
}
});

这是禁用您的输入并设置为触摸工作..

于 2012-12-18T18:31:34.167 回答