zoukankan      html  css  js  c++  java
  • android EditText或AutoCompleteTextView setOnKey事件问题

    今天 修改项目想把首页搜索改下,当用户输入完关键字按下软件键盘回车后跳转结果页

    代码没问题不知道为什么老是跳转二次,Debug调试发现setOnKeyListener执行二次一直未找到解决办希望有遇到这问题的人指教下

    最后查了下中文版的API发现有一个setOnEditorActionListener事件

    我把搜索事件setOnKeyListener改为setOnEditorActionListener事件

    然后把XML改为 

    <EditText
    android:id="@+id/searbox"
    style="@style/indexsearchbox"
    android:layout_toLeftOf="@id/searchbtn"
    android:hint="@string/pleasekey" 
    android:layout_height="45dip"
    android:singleLine="true"
    android:imeOptions="actionGo"/>这个意思是将软件键盘上的回车键改为GO
    

      

    代码:

    //单击软件键盘回车事件

    //单击软件键盘回车事件
    	    txtkeyword.setOnEditorActionListener(new EditText.OnEditorActionListener() { 
    			@Override
    			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    				// TODO Auto-generated method stub
    				if(actionId ==EditorInfo.IME_ACTION_GO){
    					 //跳转activity
    					return true;
    					}else{
    						Toast.makeText(context, R.string.key_word, Toast.LENGTH_SHORT).show(); 
    
    						return true;
    					}
    				}  
    				return false;
    			}
    		});
    

      

    在测试与调试没问题成功。

    就这一个跳转二次问题折腾几个小时 哎。。。。

  • 相关阅读:
    javascript获取时间差
    鼠标上下滚动支持combobox选中
    用 CSS 实现元素垂直居中,有哪些好的方案?
    easyui form load 数据表单有下拉框
    Javascript 严格模式详解
    artTemplate 原生 js 模板语法版
    artTemplate 简洁语法版
    mysql 选择性高
    mysql 事件调度器
    Windows 抓取本地环路包
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/2425439.html
Copyright © 2011-2022 走看看