It is necessary in the program code to call the input method selection window. How can I do that? If through intent-filters, then by what word?

I explain: I have an edittext in which I intercept clicks using onTouch. In the OnTouch method, I invoke the keyboard and perform a few more actions. However, the ability to select the input method with a long press on edittext was lost. Here, I'm trying to get her back.

Code:

EditText et = (EditText) findViewById(R.id.answer); et.setOnTouchListener(this); public boolean onTouch(View v, MotionEvent me) { Answer.super.onTouchEvent(me); //Пытаюсь обработать нажатие по обычному, но безуспешно if (me.getAction() == MotionEvent.ACTION_DOWN & v.getId() == R.id.answer) { Answer.super.onTouchEvent(me); EditText et = (EditText) findViewById(R.id.answer); // Показ клавиатуры InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(et, 0); //Как раз то, ради чего создавался OnTouch: ((LockableScrollView)findViewById(R.id.scroll)).setScrollingEnabled(true); return true; } else if (me.getAction() == MotionEvent.ACTION_UP) { Answer.super.onTouchEvent(me); ((LockableScrollView)findViewById(R.id.scroll)).setScrollingEnabled(true); return true; } Answer.super.onTouchEvent(me); return false; } 
  • it's not entirely clear what you want to do, you can make a choice through dialogue - explain what you want to do - gadfil
  • > In the OnTouch method, why do I call the keyboard? - Gorets
  • Because I need to click on EditText to do all the standard actions + a few more (which is why I had to intercept the press using OnTouch). If I do not call it programmatically, then it will not be called at all. - Tuhlom
  • show better code - Gorets

2 answers 2

Found the same solution: the call to the input method selection window is called with just one line of code:

 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showInputMethodPicker(); 

    well, the code wants to be better =)

      EditText et = (EditText) findViewById(R.id.answer); et.setOnTouchListener(this); public boolean onTouch(View v, MotionEvent me) { // Answer.super.onTouchEvent(me); //Пытаюсь обработать нажатие по обычному, но безуспешно - это совсем не по обычному, так как у тебя слушатель прицеплен только к одной View, будет обрабатываться то что надо. if (me.getAction() == MotionEvent.ACTION_DOWN) { // Answer.super.onTouchEvent(me); непонятно зачем // EditText et = (EditText) findViewById(R.id.answer); зачем еще раз искать его?? // Показ клавиатуры // InputMethodManager imm = (InputMethodManager) // getSystemService(Context.INPUT_METHOD_SERVICE); // imm.showSoftInput(et, 0); сама должна выехать //Как раз то, ради чего создавался OnTouch: это я даже не представляю что такое ) ((LockableScrollView)findViewById(R.id.scroll)).setScrollingEnabled(true); return true; } else if (me.getAction() == MotionEvent.ACTION_UP) { Answer.super.onTouchEvent(me); ((LockableScrollView)findViewById(R.id.scroll)).setScrollingEnabled(true); return true; } // Answer.super.onTouchEvent(me); тоже лишнее return false; } 
    • With this code, nothing works at all - neither long press nor short. That is, the keyboard is not shown, the choice of input method is not called. And Answer.super.onTouchEvent (me) I crammed everywhere, I thought, maybe at least in one place I would transfer the processing to an ordinary click on EditText, but no. - Tuhlom
    • it means an error in another place, in my example, if you throw out all comments, then the method should work out, try to rewrite et.setOnTouchListener (new View.OnTouchListener () {@Override public boolean onTouch (View v, MotionEvent event) {.. ..); - Gorets