-
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.setHint("请输入账号");
-
-
-
m_EditText.setOnKeyListener(new EditText.OnKeyListener() {
-
public boolean onKey(View arg0, int arg1, KeyEvent arg2)
-
{
-
-
-
-
return false;
-
}
-
});
-
-
m_EditText.setOnFocusChangeListener(new OnFocusChangeListener() {
-
-
public void onFocusChange(View v, boolean hasFocus) {
-
-
mNumber = ((EditText)v).getText().toString();
-
Log.d(TAG, "mNumber = " + mNumber);
-
getPeople();
-
}
-
-
});
-
-
m_EditText.addTextChangedListener(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) {
-
-
-
m_TextView.setText("文本框中内容是:" + m_EditText.getText().toString());
-
}
-
-
});
-
}
-
-
-
-
-
public void getPeople() {
-
String[] projection = { ContactsContract.PhoneLookup.DISPLAY_NAME,
-
ContactsContract.CommonDataKinds.Phone.NUMBER};
-
-
Log.d(TAG, "getPeople ---------");
-
-
-
Cursor cursor = this.getContentResolver().query(
-
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
-
projection,
-
ContactsContract.CommonDataKinds.Phone.NUMBER + " = '" + mNumber + "'",
-
null,
-
null);
-
-
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);
-
m_TextView.setText("联系人姓名:" + name);
-
}
-
}
-
-
}