当前位置: 代码迷 >> Android >> android edittext 点击回车能响应两次的解决方案
  详细解决方案

android edittext 点击回车能响应两次的解决方案

热度:229   发布时间:2016-04-28 01:42:15.0
android edittext 点击回车会响应两次的解决方案

由于Key有Down和Up事件,所以会执行两次。

class editTextOnKeyClickListener implements etOnKeyClickListener {        @Override        public boolean onKeyClick(View v, int keyCode, KeyEvent event) {            // TODO Auto-generated method stub            if (keyCode == KeyEvent.KEYCODE_ENTER&& event.getAction() == KeyEvent.ACTION_DOWN) {                InputMethodManager imm = (InputMethodManager) v.getContext()                        .getSystemService(Context.INPUT_METHOD_SERVICE);                key = search_edit_text.getText().toString();                if (imm.isActive()) {                    imm.hideSoftInputFromWindow(v.getApplicationWindowToken(),                            0);                }                load_view.setVisibility(View.VISIBLE);                page = 0;                SearchBookAsyncTask task = new SearchBookAsyncTask(key,                        load_view, view, myBookList, search_book_adapter, page,                        null, null, 0, list, showList,bg);                task.execute();            }            return false;        }    }
  相关解决方案