1
我只想邀請朋友加入我的應用程序,以便他們也可以使用該應用程序。爲此,我得到所有的聯繫人,但問題是聯繫人正在重複。有些聯繫人顯示2次,有些則顯示3次和4次。我想我應該查詢「group by」,以便不會顯示重複項,但我很困惑在哪裏放置該查詢。 這裏是我的代碼:檢索聯繫人時出現重複聯繫人問題
private ArrayList<String> conNames;
private ArrayList<String> conNumbers;
private Cursor crContacts;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.invite);
conNames = new ArrayList<String>();
conNumbers = new ArrayList<String>();
crContacts = ContactHelper.getContactCursor(getContentResolver(), "");
crContacts.moveToFirst();
while (!crContacts.isAfterLast()) {
conNames.add(crContacts.getString(1));
conNumbers.add(crContacts.getString(2));
crContacts.moveToNext();
}
setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,
R.id.tvNameMain, conNames));
}
private class MyAdapter extends ArrayAdapter<String> {
public MyAdapter(Context context, int resource, int textViewResourceId,
ArrayList<String> conNames) {
super(context, resource, textViewResourceId, conNames);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = setList(position, parent);
return row;
}
private View setList(int position, ViewGroup parent) {
LayoutInflater inf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inf.inflate(R.layout.liststyle, parent, false);
TextView tvName = (TextView) row.findViewById(R.id.tvNameMain);
final TextView tvNumber = (TextView) row.findViewById(R.id.tvNumberMain);
tvName.setText(conNames.get(position));
tvNumber.setText(conNumbers.get(position));
return row;
}
}
指導我該怎麼辦避免重複的聯繫人
好吧,先生我得到你,讓我試試這個 –
工程就像一個魅力。謝謝:) –
@ArslanAli歡迎兄弟 – eLemEnt