在TextView单击上启动EditText输入

时间:2015-08-27 12:10:44

标签: android

当您单击TextView时,有没有办法启动EditText输入(显示键盘以在EditText字段中输入文本)?

        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               ...
            }
        });

6 个答案:

答案 0 :(得分:3)

试试这个

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    if (inputMethodManager != null) {
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
       }

答案 1 :(得分:2)

尝试这样的事情:

textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               myEditTextView.requestFocus();
               InputMethodManager imm = (InputMethodManager) MyActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
               imm.showSoftInput(myEditTextView, InputMethodManager.SHOW_IMPLICIT);
            }
        });

答案 2 :(得分:1)

以下代码段可能有所帮助:

InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

答案 3 :(得分:1)

EditText edittext = (EditText ) findViewById(R.id.myTextViewId);
EditText textView = (EditText ) findViewById(R.id.textView);
textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

          edittext.requestFocus();
          InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.showSoftInput(textView, InputMethodManager.SHOW_IMPLICIT);
        }
    });

答案 4 :(得分:1)

          etInput.requestFocus();
          InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.showSoftInput(etInput, InputMethodManager.SHOW_IMPLICIT);

您需要添加 InputMethodManager.SHOW_IMPLICIT

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html

答案 5 :(得分:0)

onview Of Textview

textView.setOnClickListener(new View.OnClickListener() 
{  
    public void onClick(View v) {
        openKeyboard();
    }
});

打开键盘的方法

private void openKeyboard() {
    etInput.requestFocus();
    final InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(etInput, InputMethodManager.SHOW_IMPLICIT);
}