How can I change keyboard layout in onSwipe method?

I would like to know how to change the keyboard layout in a method onSwipe

.
I have qwerty.xml

letters, but I need numbers and symbols.
These two groups of characters are found in numeric.xml

.
numeric.xml

will be displayed and qwerty.xml

will be hidden when scrolling left or right.

If you need any part of my code, please ask.

+3


source to share


1 answer


You need to change layout to your keyboard object in InputManagerService. Then you need to invalidate all keys for the keyboard to be redrawn. For example:



 public class MyKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener
 {

    private KeyboardView myKeyboardView;
    private Keyboard myKeyboard;

    public View onCreateInputView()
    {

       viewOfKeyboard = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard1, null);
       theKeyboardLayout = new Keyboard(this, R.xml.keyboardlayout);
       viewOfKeyboard.setKeyboard(theKeyboardLayout);
       viewOfKeyboard.setOnKeyboardActionListener(this);
       return myKeyboardView;
    }

    public void swipeRight()
    {
       if(isQwerty)
       {
         myKeyboard = new Keyboard(this, R.xml.numeric);
         //Creates a new keyboard object.
         myKeyboardView.setKeyboard(myKeyboard);
         //Assigns the new keyboard object to the keyboard view
         myKeyboardView.invalidateAllKeys();
         //Makes android redraw the keyboard view, with the new layout.
         isqwerty = false;
       }
       else
       {
         myKeyboard = new Keyboard(this, R.xml.qwerty); 
         myKeyboardView.setKeyboard(myKeyboard);
         myKeyboardView.invalidateAllKeys();
         isqwerty = true;
       }

       //.........the rest of MyKeyboard methods     

    }

      

+2


source







All Articles