2011-02-01 74 views
0

我有一个edittext视图,其默认文本值如'输入值'。当用户触摸edittext时,我想清除edittext的值并向用户显示虚拟键盘。虚拟键盘问题

我这样做,它仍然无法正常工作。任何人都可以告诉我如何做到这一点?

@Override 
    public boolean onTouch(View arg0, MotionEvent arg1) { 
     // TODO Auto-generated method stub 
     edtsearch.setText(""); 
     //((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(edtsearch, 0); 
     InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
     mgr.showSoftInput(edtsearch, InputMethodManager.SHOW_IMPLICIT); 

     return true; 
    } 

上面的代码没有显示键盘。任何人都可以告诉我如何清除数值并向用户显示键盘吗?

即使我使用android:提示键盘时只有点击它清除值。如果用户触摸编辑文本框,则需要清除该值并将键盘显示给用户。

回答

1

您期待的是Android EditText的默认行为。

你不要有任何事情

  1. 刚刚从你的代码

  2. 删除onTouch方法保持hint

这就是你需要的。

+0

@mohan这是[提示属性]的文档(http://developer.android.com/reference/android/widget/TextView.html#attr_android:hint) – 2011-02-01 16:25:29