public class AndroidTest extends Activity {
private static final String TAG = "AndroidTest";
private TextView m_TextView;
private EditText m_EditText;
private String mNumber;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_TextView = (TextView) findViewById(R.id.TextView01);
m_EditText = (EditText) findViewById(R.id.EditText01);
m_TextView.setTextSize(20);
/**
* 设置当m_EditText中为空时提示的内容
* 在XML中同样可以实现:android:hint="请输入账号"
*/
m_EditText.setHint("请输入账号");
/* 设置EditText事件监听 */
m_EditText.setOnKeyListener(new EditText.OnKeyListener() {
public boolean onKey(View arg0, int arg1, KeyEvent arg2)
{
// TODO Auto-generated method stub
// 得到文字,将其显示到TextView中
// m_TextView.setText("文本框中内容是:" + m_EditText.getText().toString());
return false;
}
});
m_EditText.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
mNumber = ((EditText)v).getText().toString();
Log.d(TAG, "mNumber = " + mNumber);
getPeople();
}
});
m_EditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
// 得到文字,将其显示到TextView中
m_TextView.setText("文本框中内容是:" + m_EditText.getText().toString());
}
});
}
/*
* 根据电话号码取得联系人姓名
*/
public void getPeople() {
String[] projection = { ContactsContract.PhoneLookup.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER};
Log.d(TAG, "getPeople ---------");
// 将自己添加到 msPeers 中
Cursor cursor = this.getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
projection, // Which columns to return.
ContactsContract.CommonDataKinds.Phone.NUMBER + " = '" + mNumber + "'", // WHERE clause.
null, // WHERE clause value substitution
null); // Sort order.
if( cursor == null ) {
Log.d(TAG, "getPeople null");
return;
}
Log.d(TAG, "getPeople cursor.getCount() = " + cursor.getCount());
for( int i = 0; i < cursor.getCount(); i++ )
{
cursor.moveToPosition(i);
// 取得联系人名字
int nameFieldColumnIndex = cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME);
String name = cursor.getString(nameFieldColumnIndex);
Log.i("Contacts", "" + name + " .... " + nameFieldColumnIndex); // 这里提示 force close
m_TextView.setText("联系人姓名:" + name);
}
}
}
原文链接:http://blog.csdn.net/ameyume/archive/2010/12/11/6068983.aspx
分享到:
相关推荐
Android2.2通讯录源码,系统自带的
android2.2源码编译-Ubuntu10.04 (X86) + android2.2 + JDK1.6android2.2源码编译-Ubuntu10.04 (X86) + android2.2 + JDK1.6android2.2源码编译-Ubuntu10.04 (X86) + android2.2 + JDK1.6
android2.2源码 安卓2.2系统源代码 内附使用说明
android 2.2 源代码 关联eclipse使用超爽
lockscreen application for android 2.2
Android 2.2 API 中文文档
android2.2 adb工具; 适用于大部分机子(中兴v880测试通过)。
最新出炉的 Google在旧金山Moscone会展中心举办Google I/O 2010...Android 2.2是非常值得期待,下面是根据个人实践经验配置Android SDK2.2+Eclipse 的开放环境编写的详细步骤。根据这些步骤,就是门外汉也可有完成。
android2.2sdk1共2个 android2.2sdk1共2个android2.2sdk1共2个
MyEclipse Android2.2- 2.3 开发环境搭建、配置 (基于Win 7、xp、win2003操作系统) 一、基本步骤概览 1、安装MyEclipse8.5 (集成了Eclipse 3.5.2) 2、安装和配置Android SDK 2.2 3、安装ADT 4、配置...
在SDK的安装文件目录中的android 2.2中新建一个sources文件夹,将下载的源代码解压到此文件夹中,重启eclipse即可。一下路径为本人的SDK安装目录: E:\android\android-sdk-windows\platforms\android-8\sources
Android 2.2 源码 ,android-2.2-froyo-src.zip/android-2.2-froyo-src.zip
用于android2.2 用eclipse调试,获取本机号码的话,非移动用户可以获得,移动用户获取不到,可以获取本机联系人信息,并拨打其电话
eclipse时,debug中经常会遇到source not ...一般的解决方法是将android源代码,添加到D:\Android\android-sdk-windows\platforms\android-8中,本资源分为四个部分,一并下载后解压合并即可android2.2源代码(part1)
android2.2通讯录操作源代码,经验证可行。欢迎使用
android2.2 源码 覆盖网络应用 界面操作 后台管理 直接导入就可以用了
android-2.2源码(保证是正确的) 你可以代码关联。
Android 2.2 即 API-8 的源代码。 用7zip格式压缩,120多M的东西压得只有10几M了。
android 2.2 中文排序包.....
android2.2源代码下载,将下载的文件sources.rar解压后放置在android.jar所在目录中。如\android-sdk-windows\platforms\android-8\sources\...包...。 源码包含了android.jar中android包以及apache包的所有源文件。