我想訪問帶有名稱的電話號碼。但是當我這樣做時,我的通話不符合我選擇的號碼。我有一個帶有複選框的列表視圖。用戶的選擇名稱並且這些名字轉到次數第二個活動。我的問題是第二個活動中的數字和名字選擇在第一個活動。當我打電話給任何名字,我的應用程序調用不同的數字。我可以如何解決它?聯繫人名稱不匹配在列表視圖中的數字
ArrayList<String> listte = new ArrayList<String>();
ArrayList<String> selectedlist = new ArrayList<>();
ListView chosinglist;
Button kaydet;
ArrayList<String> listtearama = new ArrayList<>();
ArrayList<String> selectedlistarama = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chosinglist = (ListView) findViewById(R.id.chosing);
chosinglist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
getNumber(this.getContentResolver());
}
private void getNumber(ContentResolver contentResolver) {
Cursor phones = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
while (phones.moveToNext()) {
String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phonenumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
System.out.println(".................." + phonenumber);
if (!listte.contains(name)){ // it doesn"t work.But if It doesn"t exist, listview is repeating yourself.
listte.add(name);
}
if (!listtearama.contains(phonenumber)){// it doesn"t work.But if It doesn"t exist, listview is repeating yourself.
listtearama.add(phonenumber); }
}
phones.close();// close cursor
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.checkrow,
R.id.checkedTextView2, listte);
chosinglist.setAdapter(adapter);
chosinglist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selecteditem = (String) parent.getAdapter().getItem(position);
int arkaplandakinumaraposition = parent.getPositionForView(view);
String aramakicinliste = listtearama.get(arkaplandakinumaraposition);
if (selectedlistarama.contains(aramakicinliste)) {
selectedlistarama.remove(aramakicinliste);
} else
selectedlistarama.add(aramakicinliste);
if (selectedlist.contains(selecteditem)) {
selectedlist.remove(selecteditem);
} else selectedlist.add(selecteditem);
爲您的問題添加一個android,java標籤,以供更多人表現出興趣。此外,你的代碼不是很具描述性,所以你很難掌握你在做什麼,嘗試使用描述性變量名稱或評論 –
好的我添加了android標籤。 –
ok.I編輯我的codo一點點。如果你是thinging.just說 –