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));
// 获取联系人的讯录socket编程c源码名字
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.
2025-01-31 13:211647人浏览
2025-01-31 13:181087人浏览
2025-01-31 12:06494人浏览
2025-01-31 12:011674人浏览
2025-01-31 11:542894人浏览
2025-01-31 11:47540人浏览
中国消费者报福州讯陈琼英记者张文章)一次性使用静脉输液针过期了大半年,白蛋白测定试剂盒早在2022年12月14日就已失效,但这些医疗器械仍摆放在医疗美容机构的配剂室、专用冰箱内待用。2月3日,福建省厦
1.在源码编辑器中,一个东西克隆出了好几个,如何让克隆体消失,并且只消失一个?2.刮码和源码有什么区别3.梳理 | 代码克隆检测技术4.Android studio从Github克隆下载源代码并导入的
1.gw-basic语法2.fnf是什么3.股票FNF轨道线怎么找gw-basic语法 GW-BASIC提供了一个直观且基础的集成开发环境IDE)。每行程序代码都需要包含行号,未标注行号的语句被认