现在我有CustomKeyboard class(view)
并且我有自定义中文字符。
我也有几个ToggleButton
。我想实现一些东西,如果我点击中文键盘的中文选项,它会将我的toggleButton切换为“ON”。
但我不确定如何将它们连接在一起。
//CustomKeyboard.java/class - This is the java file that is use for my CustomKeyboardView. This works when onClick on the Keyboard itself, it'll change the keyboard view etc.
private OnKeyboardActionListener noncapitalKeyboard = new OnKeyboardActionListener() {
public final static int CodeNext = 55005;
public final static int CodeClear = 55006;
public final static int CodeCapital = 55007;
public final static int CodeSymbol = 55008;
public final static int CodeABC = 55009;
public final static int CodeChinese1 = 55010;
@Override public void onKey(int primaryCode, int[] keyCodes) {
// NOTE We can say '<Key android:codes="49,50" ... >' in the xml file; all codes come in keyCodes, the first in this list in primaryCode
// Get the EditText and its Editable
View focusCurrent = mHostActivity.getWindow().getCurrentFocus();
if( focusCurrent==null || focusCurrent.getClass()!=EditText.class ) return;
EditText edittext = (EditText) focusCurrent;
Editable editable = edittext.getText();
int start = edittext.getSelectionStart();
// Apply the key to the edittext
if(primaryCode == CodeCapital){
mKeyboardView= (KeyboardView)mHostActivity.findViewById(R.id.keyboardview);
mKeyboardView.setKeyboard(new Keyboard(mHostActivity, R.xml.capitalkeyboard));
mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview balloons
mKeyboardView.setOnKeyboardActionListener(capitalKeyboard);
}else if(primaryCode == CodeSymbol){
mKeyboardView= (KeyboardView)mHostActivity.findViewById(R.id.keyboardview);
mKeyboardView.setKeyboard(new Keyboard(mHostActivity, R.xml.symbolkeyboard));
mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview balloons
mKeyboardView.setOnKeyboardActionListener(symbolKeyboard);
}else if(primaryCode == CodeChinese1){
mKeyboardView= (KeyboardView)mHostActivity.findViewById(R.id.keyboardview);
mKeyboardView.setKeyboard(new Keyboard(mHostActivity, R.xml.chinese1keyboard));
mKeyboardView.setPreviewEnabled(false); // NOTE Do not show the preview balloons
mKeyboardView.setOnKeyboardActionListener(chinese1Keyboard);
}
但是在我的主UI线程上,我如何带来像
if(primaryCode == CodeChinese1){
toggleButton1.setChecked(true);
}
我尝试在我的主java文件上实现OnKeyboardActionListener,但它没有用,因为它没有引用我的CustomKeyboard。我需要创建一个界面吗?