Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何隐藏键盘、向EditText添加文本和移动光标_Android_Android Layout_Android Edittext_Android Button_Android Cursor - Fatal编程技术网

Android 如何隐藏键盘、向EditText添加文本和移动光标

Android 如何隐藏键盘、向EditText添加文本和移动光标,android,android-layout,android-edittext,android-button,android-cursor,Android,Android Layout,Android Edittext,Android Button,Android Cursor,我有一个编辑文本和一个按钮。当您按下EditText时,我不想显示键盘,当您按下按钮时,我想在EditText上键入数字1 我想要的观察并没有消失 @卡里姆·米歇尔。你可以用 setCursorVisible(false); setText("1"); 对于第一种情况,隐藏键盘 ETOBJ.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch

我有一个编辑文本和一个按钮。当您按下EditText时,我不想显示键盘,当您按下按钮时,我想在EditText上键入数字1

我想要的观察并没有消失

@卡里姆·米歇尔。你可以用

setCursorVisible(false);
setText("1");
对于第一种情况,隐藏键盘

   ETOBJ.setOnTouchListener(new View.OnTouchListener()
        {
            public boolean onTouch(View arg0, MotionEvent arg1)
            {
                InputMethodManager inputManager = (InputMethodManager) context.
                getSystemService(Context.INPUT_METHOD_SERVICE); 
                inputManager.hideSoftInputFromWindow(
                this.getCurrentFocus().getWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS); 
                return false;
            }
        });
当按下按钮时,您可以使用

setCursorVisible(false);
setText("1");
请尝试以下代码:

your_edit_text.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            your_edit_text.setInputType(InputType.TYPE_NULL);
            EditText.setText("1");
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
             imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
             your_edit_text.setSelection(your_edit_text.getText().length()); // move cursor to end
        }

您可以使用setCursorVisiblefalse;我不想显示键盘我想通过按钮控制文本