【问题标题】:How to get all UNIQUE groups from contacts如何从联系人中获取所有 UNIQUE 组
【发布时间】:2015-04-20 07:09:22
【问题描述】:

如何从联系人中获取所有唯一组。我已经能够获取组的所有实例,但我想我在设备上拥有多个帐户,因此我收到了相同组的多个实例,例如同事、同事、同事、同事、朋友、朋友。 我试图删除 ArrayList 中的复杂项目,但我的 LinearLayout 仍然由同一组的太多实例填充。 这是我的代码...

ArrayList<String> mArrayList = new ArrayList<String>();
    final String[] GROUP_PROJECTION = new String[] {
            ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };

Cursor gCursor = getContentResolver().query(
    ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
            null, ContactsContract.Groups.TITLE);
    gCursor.moveToFirst();
    while (!gCursor.isAfterLast()) {
        int idcolumn = gCursor.getColumnIndex(ContactsContract.Groups.TITLE);
        String id = gCursor.getString(idcolumn);
        mArrayList.add(id);

LinearLayout sv = (LinearLayout) findViewById(R.id.maingridview);
        Button iv = new Button(this);
        iv.setBackgroundResource(R.drawable.yellow);
        iv.setText(id);
        sv.addView(iv);


        gCursor.moveToNext();}

【问题讨论】:

    标签: android arraylist cursor android-contacts


    【解决方案1】:

    在添加数据之前检查,

    if(!mArrayList.contains("resulted_data")){
        //add data
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多