【问题标题】:How do I remove names from my Arraylist that dont match the names from my inbox?如何从我的 Arraylist 中删除与收件箱中的名称不匹配的名称?
【发布时间】:2012-06-01 08:38:29
【问题描述】:

这是我从设备中获取联系人姓名的代码。我遇到的问题是,在我的列表视图中,“元素”将显示联系人列表中的每个姓名。关于如何删除没有 SMS 的名称的任何想法?

    // converts contacts from cursor to arraylist
    nameList = new ArrayList<String>();
    cursor = getContacts();
    while(cursor.moveToNext()){

        nameList.add(cursor.getString(cursor.getColumnIndex(
                     ContactsContract.Data.DISPLAY_NAME )));
    }

    // convert arraylist to string array
    name = new String[nameList.size()];
    name = nameList.toArray(name);

    // new arraylist for after contacts with no messages are removed
    elements = new ArrayList<String>();

    //convert back to an arraylist
    for(int i = 0; i < name.length; i++){
        elements.add(name[i]);
    }

【问题讨论】:

    标签: android string arraylist sms contacts


    【解决方案1】:

    我想您需要检索短信列表,然后与每个联系人号码进行比较,以找到每个联系人的实际短信数量。一旦你有了,你可以从列表中删除有 0 条消息的联系人。 This is a good link regarding working with SMS

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-27
      • 2021-09-05
      • 2017-01-03
      • 1970-01-01
      • 2020-07-01
      • 2012-08-14
      • 2014-04-10
      • 2016-10-19
      相关资源
      最近更新 更多