gpt4 book ai didi

Android 在发送短信时删除已选择的联系人

转载 作者:行者123 更新时间:2023-11-30 03:08:19 25 4
gpt4 key购买 nike

在我的应用程序中,我有许多 edittext View 用于从电话簿中获取联系人,当我为第一个 edittext View 选择联系人时,我不希望同一个联系人在第二个 View 中可见。怎么做。

    String selectedNum = " ";
public void showSelectedNumber(String name, String number, int type) {
if (layoutLinear == null) {
Log.i("layoutLinear is null", "null");
} else {
Log.i("layoutLinear is not null", "not null");

}

EditText userNumber = (EditText) layoutLinear.getChildAt(0);
if (userNumber == null) {
Log.i("edittext is null", "null");
} else {
Log.i("edittext is not null", "not null");

}
String typeNumber = (String) ContactsContract.CommonDataKinds.Phone
.getTypeLabel(getResources(), type, "");
//preventing number duplicacy and raising toast
if(selectedNum.contains(number)){
// do nothing
// alert user that number is already selected
Toast.makeText(getApplicationContext(), "Selected Contact Already Exists", Toast.LENGTH_SHORT).show();
}else
userNumber.setText(name+":"+number+" "+typeNumber);
selectedNum= selectedNum+number;




}



}// final parentheses

最佳答案

将选定的联系人存储在字符串中,如 String selectedContact="";

并在选择联系人时检查此字符串

if(selectedContact.contains(newContact))
{
//do nothing
}
else{
//set to edittext
and selectedContact+newContact ;
}

尝试下面的代码

String selectedNum="";//class or global variable

public void showSelectedNumber(String name, String number, int type) {
if (layoutLinear == null) {
Log.i("layoutLinear is null", "null");
} else {
Log.i("layoutLinear is not null", "not null");

}

EditText userNumber = (EditText) layoutLinear.getChildAt(0);
if (userNumber == null) {
Log.i("edittext is null", "null");
} else {
Log.i("edittext is not null", "not null");

}
String typeNumber = (String) ContactsContract.CommonDataKinds.Phone
.getTypeLabel(getResources(), type, "");
if(selectedNum.contains(number)){
// nothing to do
// alert user number already selected
}else{
userNumber.setText(name + ": " + number + " " + typeNumber);
selectedNum=selectedNum+number;
}

}

关于Android 在发送短信时删除已选择的联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21404073/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com