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));
// 获取联系人的源码我爱截图源码名字
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-12-29 16:052041人浏览
2024-12-29 16:00356人浏览
2024-12-29 15:37504人浏览
2024-12-29 14:471452人浏览
2024-12-29 13:54939人浏览
2024-12-29 13:462851人浏览
日本福岡縣北九州市一間麥當勞昨日12月14日)發生持刀傷人案,造成1名女學生死亡,1名男學生受傷送院。警方正在通緝在逃疑犯。據日本放送協會NHK)報道,事發於當地時間晚上約8時30分,一名男子衝進北九
1.zabbix是什么2.Linux软件管理-YUM工具及源码包3.网络工程师的zabbix之旅实战) -- zabbix_server5.0安装部署4.在suselinux上怎么部署zabbix5.