以编程方式调用editorActionListener

时间:2011-12-01 00:45:51

标签: android

我正在测试TextView小部件,并希望使用editorActionListener以编程方式调用已注册的textView.setOnEditorActionListener(...)集。解雇此事件的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

试试这个......可能会有所帮助..

 TextView textview=(TextView)findViewById(R.id.searchText);//searchText is the id in XML layout
 textview.setImeOptions(EditorInfo.IME_ACTION_SEARCH);// here it using for search operation..it depends upon your process
 textview.setOnEditorActionListener(new TextView.OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_SEARCH)
              {
          //peform operation..  if search key is pressed in keypad, it comes inside the condition..
            return true;
        }
        return false;
    }
});