1.android ͨѶ¼Դ?讯录?
android ͨѶ¼Դ??
1. Modify the `getTelClick()` method:
- Change the method name from `getTelClick` to `onGetTelClick` for better readability and adherence to naming conventions.
- Ensure that the method signature is correct and that it is properly calling the new method.
2. Modify the Toast breadcrumb提示:
- Remove the unnecessary string concatenation within the Toast message.
- Use string resources for the Toast message to improve localization support.
3. Modify the method for获取联系人名字:
- Correct the column index for the contact's name to match the correct field from the ContactsContract.
4. Adjust the location slightly:
- Ensure that the code for finding the contact's phone number is inside the correct `if` block to avoid unnecessary queries.
Here is the modified section of the code:
```java
// ... (previous code)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_name);
et = (EditText) this.findViewById(R.id.mobile);
}
public void onGetTelClick(View view) {
String name = et.getText().toString().trim();
getContactNumber(name);
}
/
*** 通过输入的姓名获取电话号码
*/
public void getContactNumber(String name) {
// 使用ContentResolver查找联系人数据
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
// 遍历查询结果,找到所需号码
while (cursor.moveToNext()) {
// 获取联系人ID
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
// 获取联系人的源码2020最新直播源码名字
String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
if (name.equals(contactName)) {
// 使用ContentResolver查找联系人的电话号码
Cursor phone = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{ contactId}, null);
if (phone.moveToNext()) {
String phoneNumber = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Toast.makeText(this, phoneNumber, Toast.LENGTH_SHORT).show(); // Use string resource for the message
Log.d(TAG, "电话:" + phoneNumber);
break;
}
}
}
}
```
Ensure that you have defined a string resource for the Toast message in your `res/values/strings.xml` file, like this:
```xml
电话号码:%1$s
```
And use it in the Toast.makeText method as shown above.
2024-11-20 19:081461人浏览
2024-11-20 19:00982人浏览
2024-11-20 18:51688人浏览
2024-11-20 18:012706人浏览
2024-11-20 17:061870人浏览
2024-11-20 16:49815人浏览
1.Lua5.4 源码剖析——虚拟机2 之 闭包与UpValue2.Lua5.4 源码剖析——杂谈 之 如何调试Lua源码3.怎么打开lua4.luaä¸çexeå¨åªï¼5.luade
韓團BTS防彈少年團代言知名手機,業者上個週末在台中一間百貨公司外舉辦快閃活動,衝高人氣,吸引不少粉絲前來參加,只要完成指定任務就能免費兌換限量贈品,包括三明治和印有偶像照片的飲料,不過有一位大媽因為
由美國大聯盟主辦的世界棒球經典賽WBC)受到疫情影響,延遲2年後,將在明年3月正式回歸,參賽數量也會依照2021年的規劃的16隊擴增至20隊,2017年參賽的16隊將會自動入選,剩下4隊也在今年9月的