下面是我修改之后涉及到这个输入框的源码: 1.private AutoCompleteTextView mDigits; 2.public void afterTextChanged(Editable input) { if (SpecialCharSequenceMgr.handleChars(this, input.toString(), mDigits)) { // A special sequence was entered, clear the digits mDigits.getText().clear(); } if (!isDigitsEmpty()) { mDigits.setBackgroundDrawable(mDigitsBackground); } else { mDigits.setCursorVisible(false); mDigits.setBackgroundDrawable(mDigitsEmptyBackground); } updateDialAndDeleteButtonEnabledState(); } 3.mDigits = (AutoCompleteTextView) findViewById(R.id.digits); mDigits.setKeyListener(DialerKeyListener.getInstance()); mDigits.setOnClickListener(this); mDigits.setOnKeyListener(this);
//set the auto phoneNumber adapter ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,getNumFromPhoneBook()); mDigits.setAdapter(adapter); 代码太多了,都是android系统的源码。。好麻烦
public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing } public void onTextChanged(CharSequence input, int start, int before, int changeCount) { // Do nothing*#06# // DTMF Tones do not need to be played here any longer - // the DTMF dialer handles that functionality now. mHandler.sendEmptyMessage(0); } public void afterTextChanged(Editable input) { if (SpecialCharSequenceMgr.handleChars(this, input.toString(), mDigits)) { // A special sequence was entered, clear the digits mDigits.getText().clear(); } if (!isDigitsEmpty()) { mDigits.setBackgroundDrawable(mDigitsBackground); } else { mDigits.setCursorVisible(false); mDigits.setBackgroundDrawable(mDigitsEmptyBackground); } mHandler.sendEmptyMessageDelayed(1, 1000); updateDialAndDeleteButtonEnabledState(); }
1.private AutoCompleteTextView mDigits;
2.public void afterTextChanged(Editable input) {
if (SpecialCharSequenceMgr.handleChars(this, input.toString(), mDigits)) {
// A special sequence was entered, clear the digits
mDigits.getText().clear();
} if (!isDigitsEmpty()) {
mDigits.setBackgroundDrawable(mDigitsBackground);
} else {
mDigits.setCursorVisible(false);
mDigits.setBackgroundDrawable(mDigitsEmptyBackground);
} updateDialAndDeleteButtonEnabledState();
}
3.mDigits = (AutoCompleteTextView) findViewById(R.id.digits);
mDigits.setKeyListener(DialerKeyListener.getInstance());
mDigits.setOnClickListener(this);
mDigits.setOnKeyListener(this);
//set the auto phoneNumber adapter
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,getNumFromPhoneBook());
mDigits.setAdapter(adapter);
代码太多了,都是android系统的源码。。好麻烦
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch(msg.what){
case SEARCHING_STATE:
lbMsg.setText(TwelveKeyDialer.this.getResources().getString(R.string.search_results_searching));
bar.setVisibility(View.VISIBLE);
break;
case SEARCHED_STATE:
Uri uri1 = ContactsContract.Contacts.CONTENT_URI;
Uri uri2 = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor cursor = TwelveKeyDialer.this.getContentResolver().query(uri2, null, ContactsContract.CommonDataKinds.Phone.NUMBER + " like '%" + mDigits.getText().toString().replace("-", "").trim() + "%'", null, null);
String strID = null;
String displayName = null;
String phoneNum = null;
if(cursor.moveToNext()){
strID = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
phoneNum = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
cursor.close();
Cursor c = TwelveKeyDialer.this.getContentResolver().query(uri1, null,ContactsContract.Contacts._ID + "=" + strID, null, null);
if(c.moveToNext()){
displayName = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
c.close();
if(null != displayName){
phoneNum = phoneNum.replace("-", "").trim();
lbMsg.setText(displayName + "\t" + phoneNum);
isExist = true;
}else{
lbMsg.setText(getResources().getString(R.string.recentCalls_addToContact) + ":" + mDigits.getText().toString());
isExist = false;
}
bar.setVisibility(View.INVISIBLE);
break;
default:break;
}
}
}我还是用的EditText,就是在下面用了个TextView来显示提示
// Do nothing
} public void onTextChanged(CharSequence input, int start, int before, int changeCount) {
// Do nothing*#06#
// DTMF Tones do not need to be played here any longer -
// the DTMF dialer handles that functionality now.
mHandler.sendEmptyMessage(0);
} public void afterTextChanged(Editable input) {
if (SpecialCharSequenceMgr.handleChars(this, input.toString(), mDigits)) {
// A special sequence was entered, clear the digits
mDigits.getText().clear();
} if (!isDigitsEmpty()) {
mDigits.setBackgroundDrawable(mDigitsBackground);
} else {
mDigits.setCursorVisible(false);
mDigits.setBackgroundDrawable(mDigitsEmptyBackground);
}
mHandler.sendEmptyMessageDelayed(1, 1000);
updateDialAndDeleteButtonEnabledState();
}