使用快速搜索框自定义键盘命令

时间:2014-02-04 10:44:45

标签: android keyboard searchbar

我有阿拉伯语和普通英语键盘的自定义键盘,可以从我的Sqlite数据库中快速搜索框搜索。 英文键盘工作正常。 但是当阿拉伯语关键字弹出窗口时,我无法输入编辑文本...

我的代码:

 public class MainActivity extends FragmentActivity {

CustomKeyboard mCustomKeyboard;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mCustomKeyboard = new CustomKeyboard(this, R.id.keyboardview,
            R.xml.hexkbd);

    View button = findViewById(R.id.btn_search_en);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearchRequested();
        }
    });

    View button1 = findViewById(R.id.btn_search_ar);
    button1.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            toggleKeyboardVisibility();
        }
    });
}

private void toggleKeyboardVisibility() {
    KeyboardView mCustomKeyboard = (KeyboardView) findViewById(R.id.keyboardview);
    int visibility = mCustomKeyboard.getVisibility();
    switch (visibility) {
    case View.VISIBLE:
        mCustomKeyboard.setVisibility(View.INVISIBLE);
        break;
    case View.GONE:
    case View.INVISIBLE:
        mCustomKeyboard.setVisibility(View.VISIBLE);
        break;
    }
}

@Override
public void onBackPressed() {
    // NOTE Trap the back key: when the CustomKeyboard is still visible hide
    // it, only when it is invisible, finish activity
    if (mCustomKeyboard.isCustomKeyboardVisible())
        mCustomKeyboard.hideCustomKeyboard();
    else
        this.finish();
}

}

如果有人帮我解决这个问题,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

您需要注册要使用键盘的每个EditText,如:

mCustomKeyboard = new CustomKeyboard(this, R.id.keyboardview,
            R.xml.hexkbd);

// register the edittext
mCustomKeyboard.registerEditText(R.id.edittext);