根据输入框的输入内容的不同,来检索本地通讯录,是按照姓名,还是手机号码!
来源:互联网 发布:c语言表达式基本类型 编辑:程序博客网 时间:2024/05/03 03:43
login.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_gravity="center" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="15.0dip"> <TextView android:text="用户名" android:textSize="20sp" android:layout_width="fill_parent" android:layout_height="wrap_content" > </TextView><!-- 311613 lw8p999aar 34171457 js7m78cwdd --> <EditText android:layout_width="fill_parent" android:text="311613" android:layout_height="40dp" android:id="@+id/userName"> </EditText> <TextView android:text="密码" android:textSize="20sp" android:layout_width="fill_parent" android:layout_height="wrap_content"> </TextView> <EditText android:layout_width="fill_parent" android:text="lw8p999aar" android:layout_height="40dp" android:id="@+id/userPassWord" android:password="true"> </EditText> <LinearLayout android:gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/logBtn" android:layout_width="60.0dp" android:layout_height="50.0dp" android:layout_gravity="center" android:text="登陆" android:focusable="true" android:layout_margin="10.0dp"> </Button> <Button android:id="@+id/cancleBtn" android:layout_width="60.0dp" android:layout_height="50.0dp" android:text="取消" android:layout_margin="10.0dp"> </Button> </LinearLayout> </LinearLayout></LinearLayout>
首先,先要让输入框获得焦点,然后间隔1秒钟后,弹出软键盘
其次,根据输入框的输入内容的不同。来响应的检索
package com.shen;import java.util.Timer;import java.util.TimerTask;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.text.Editable;import android.text.TextWatcher;import android.util.Log;import android.view.KeyEvent;import android.view.inputmethod.InputMethodManager;import android.widget.EditText;public class MainActivity extends Activity {/** Called when the activity is first created. */private InputMethodManager imm = null;private EditText login_Edittext;private static String debug = "MainActivity";@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.login);imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);login_Edittext = (EditText) findViewById(R.id.userName);login_Edittext.requestFocus();Timer timer = new Timer(); // 设置定时器timer.schedule(new TimerTask() {@Overridepublic void run() { // 弹出软键盘的代码imm.showSoftInput(login_Edittext,InputMethodManager.HIDE_NOT_ALWAYS);imm.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT);}}, 300); // 设置300毫秒的时长login_Edittext.addTextChangedListener(changeWather);// List<InputMethodInfo> infoList = imm.getInputMethodList();// infoList.size();// List<InputMethodInfo> enableList = imm.getEnabledInputMethodList();// enableList.size();// Log.e(debug, "infoList.size()==" + infoList.size());// Log.e(debug, "enableList.size()==" + enableList.size());// InputMethodInfo info=enableList.get(0);// info.}@Overridepublic boolean dispatchKeyEvent(KeyEvent event) {Log.e(debug, "event.getAction()==" + event.getAction());return super.dispatchKeyEvent(event);}private TextWatcher changeWather = new TextWatcher() {public void afterTextChanged(Editable s) {}public void beforeTextChanged(CharSequence s, int start, int count,int after) {}public void onTextChanged(CharSequence s, int start, int before,int count) {String textValue = login_Edittext.getText().toString();if (textValue.length() > 0) {//if (isChineseEnglish(textValue.charAt(0))) {//Log.e(debug, "按照中文搜索******");//} else {//Log.e(debug, "按照英文来搜索==========");//}//isChinese(textValue);hasChinese(textValue);//Log.e(debug, isChinese(textValue));}};};/** * 判断一个字符是中文还是英文 * @param c * @return */public static boolean isChineseEnglish(char c) {if (c >= 0 && c <= 9) {// 是数字return false;//"是数字字符";} else if ((c >= 'a' && c <= 'z')) { // 是小写字母return false;//"是小写字母";} else if ((c >= 'A' && c <= 'z')) { // 是大写字母return false;//"是大写字母";} else if (Character.isLetter(c)) { // 是汉字return true;//"是汉字字符";} else { // 是特殊符号return false;//"是特殊符号";}}/** * 判断一个字符串中是否含有中文 * @param chinese * @return */static public String isChinese(String chinese) {String ucode = " ";String strChinese = " ";String strASC = " ";try {int clen;clen = chinese.length(); // 取字符串长度String utemp = " ";char[] strBuffer = chinese.toCharArray(); // 将字符串转化为字符数组int l; // 每个字符转换后的二进制字符串的长度int s;for (int i = 0; i < clen; i++) {s = (int) strBuffer[i]; // 取一个字符utemp = Integer.toHexString(s).toUpperCase();l = utemp.length();if (l <= 2) { // 如果是ASC字符utemp = "00 " + utemp;// 保存ASC字符到strASCstrASC += chinese.substring(i, i + 1);} else {// 保存中文字符到strChinesestrChinese += chinese.substring(i, i + 1);}ucode = ucode + utemp;}System.err.println(strASC);System.err.println(strChinese);} catch (Exception e) {e.printStackTrace();}return strChinese;} public void hasChinese(String str){System.out.println(str.length()==str.getBytes().length? "English ": "Chinese ");}}
- 根据输入框的输入内容的不同,来检索本地通讯录,是按照姓名,还是手机号码!
- ios实现支持通讯录的手机号码输入弹出框
- jquery 输入框 根据输入内容检索 下拉提示
- 输入姓名成绩并按照从小到大的顺序输出
- 根据输入的值进行动态检索
- UITableViewCell上的输入框,输入不同内容
- 根据输入框EditText是否有内容来对按钮的点击权限控制
- 根据输入框中的内容更改return的显示内容
- 根据输入的内容打印出菱形
- 百度地图根据输入的内容定位
- 根据输入的内容指向不同的函数,最后一次调用完成
- 根据用户使用的是iphone还是ipad来设置显示内容的大小
- c# 判断输入的号码是否是合法的手机号码
- c# 判断输入的号码是否是合法的手机号码
- C# 控制手机号码的输入
- iOS手机号码的正确输入
- 验证输入的手机号码是否合法
- 输入学生个数,学生姓名和他们的成绩,然后按照学生成绩降序排列
- ConcurrentModificationException 异常
- 页面跳转,特别是struts.xml中result带参数实现
- CSS Sprites + 圆角
- UML中的关系
- 在S2SH整合中如何对其多表联合查询出来的数据,进行分页和排序
- 根据输入框的输入内容的不同,来检索本地通讯录,是按照姓名,还是手机号码!
- VisionMobile:智能手机和难以捉摸的长尾手机出货情况
- 如何解决在java开发中java代码和jsp页面中出现路径因为项目名称的变化(也就是应用名)的问题?
- 视频监控管理平台 引领“前台”的步伐在加快
- Hibernate悲观锁与乐观锁
- DWR3 学习笔记 - 第一个DWR3程序(扩展)
- FusionCharts_Evaluation.zip
- Oracle 用户、角色、权限
- CreateEvent使用总结