如何让在callLog.calls最频繁的值项的数量? [英] how to get the number of the most frequent value entry in callLog.calls?

查看:521
本文介绍了如何让在callLog.calls最频繁的值项的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 呼叫日志呼叫项是这个

  - 所谓的名称号码类型日期
  - 杰德12345呼入2013年7月18日
  - 罗杰14611传入二○一三年七月一十八日
  - 杰德12345呼入2013年7月18日
  - 杰德12345呼入2013年7月18日
 凯文 -  11111传入二零一三年七月十八日
 

你好,我想在这样的Andr​​oid查询,我将只检索 杰德,12345<<因为他有最重复的值在列表中, IM想做到这一点的源码(安卓查询),但我不知道调用哪个函数 这是$ C $词使用,但我只能拿到最近数调用,而不是一个与大多数项。我该怎么做查询?

 日期日期=新的日期();

    光标C = contxt.getContentResolver()查询(CallLog.Calls.CONTENT_URI,
            空,CallLog.Calls.TYPE +和+ CallLog.Calls.INCOMING_TYPE +
            与+ CallLog.Calls.Date +&GT =+ date.getDate(),
            空值,
            CallLog.Calls.DATE +DESC LIMIT 1);
    如果(C!= NULL)
        做{
            INT callCounter = c.getCount();
            字符串NUM = callLog_cursor.getString(callLog_cursor
                .getColumnIndex(android.provider.CallLog.Calls.NUMBER));
        }而(c.moveToFirst());
 

解决方案

如果你正在寻找一个查询做的工作,我很抱歉地说,它(据SA我的谷歌技能云)没有按'吨存在。我在这,你可能会发现有用的另一种方式解决了这个问题。

在您的活动的地方创建这个功能:

 公共静态无效searchAndDisplay(ArrayList中<字符串> ARR){

    ArrayList的<字符串> List1中=新的ArrayList();
    ArrayList的<整数GT; list2中=新的ArrayList();
    的for(int i = 0; I< arr.size();我++){
        INT指数= list1.indexOf(arr.get(ⅰ));
        如果(索引!= -1){
            INT newCount = list2.get(指数)+ 1;
            list2.set(索引,newCount);
        } 其他 {
            list1.add(arr.get(ⅰ));
            list2.add(1);
        }
    }
    的for(int i = 0; I< list1.size();我++){
        的System.out.println(号码+ list1.get(ⅰ)+发生
                + list2.get(ⅰ)+倍。);

    }
    INT MAXCOUNT = 0;
    INT指数= -1;
    的for(int i = 0; I< list2.size();我++){
        如果(MAXCOUNT&其中; list2.get(ⅰ)){
            MAXCOUNT = list2.get(ⅰ);
            指数=我;
        }
    }
    的System.out.println(编号+ arr.get(指数)
            +具有最高的出现即+ MAXCOUNT); //这里,你可能想要做的事/回报最高的事件再度发生的数量。
}
 

然后在您想要的鼠标,你使用这样的:

 日期日期=新的日期();
    ArrayList的<字符串> allnumbers =新的ArrayList();
    光标C = this.getContentResolver()查询(
            CallLog.Calls.CONTENT_URI,
            空值,
            CallLog.Calls.TYPE +和+ CallLog.Calls.INCOMING_TYPE
                    +和+ CallLog.Calls.DATE +&GT =+ date.getDate(),
            空,CallLog.Calls.NUMBER);

    allnumbers.clear();
    如果(C!= NULL)
        c.moveToFirst();
    的for(int i = 0; c.getCount()>我;我++){

        串数字1 = c.getString(0);

        allnumbers.add(数量1);
        c.moveToNext();

    }
    sea​​rchAndDisplay(allnumbers);
 

您可能要仔细检查您收到的数字是正确的。

让我知道如何去。 :)

Call Log Calls entry is this

 - Name        Number         TYPE          date called
 - Jed         12345          Incoming      7-18-2013
 - Roger       14611          Incoming      7-18-2013
 - Jed         12345          Incoming      7-18-2013
 - Jed         12345          Incoming      7-18-2013
 - Kevin       11111          Incoming      7-18-2013

Hi, i want to query in android such that i will only retrieve Jed, 12345 << since he has the most repetitive value in the list, im suppose to do this in sqlite (android query) but i dont know which functions to invoke This is the code i used, but i was only able to get the recent number that called instead of the one with the most entries. HOW DO I DO THE QUERY?

    Date date=new Date() ;  

    Cursor c = contxt.getContentResolver().query(CallLog.Calls.CONTENT_URI,
            null, CallLog.Calls.TYPE + " AND " + CallLog.Calls.INCOMING_TYPE + 
            " AND " + CallLog.Calls.Date + ">=" + date.getDate() ,
            null,
            CallLog.Calls.DATE + " DESC LIMIT 1");
    if(c!=null)
        do{
            int callCounter = c.getCount();
            String num = callLog_cursor.getString(callLog_cursor
                .getColumnIndex(android.provider.CallLog.Calls.NUMBER));
        }while(c.moveToFirst());

解决方案

If you're looking for a single query to do the job, I'm sorry to say that it (as far sa my google skills goes) doesn't exist. I've solved it in another way that you might find useful.

Create this function somewhere in your activity:

public static void searchAndDisplay(ArrayList<String> arr) {

    ArrayList<String> list1 = new ArrayList();
    ArrayList<Integer> list2 = new ArrayList();
    for (int i = 0; i < arr.size(); i++) {
        int index = list1.indexOf(arr.get(i));
        if (index != -1) {
            int newCount = list2.get(index) + 1;
            list2.set(index, newCount);
        } else {
            list1.add(arr.get(i));
            list2.add(1);
        }
    }
    for (int i = 0; i < list1.size(); i++) {
        System.out.println("Number " + list1.get(i) + " occurs "
                + list2.get(i) + " times.");

    }
    int maxCount = 0;
    int index = -1;
    for (int i = 0; i < list2.size(); i++) {
        if (maxCount < list2.get(i)) {
            maxCount = list2.get(i);
            index = i;
        }
    }
    System.out.println("Number " + arr.get(index)
            + " has highest occurrence i.e " + maxCount); // here you might want to do something/return the number with the highest occurences. 
}

Then where you want the cursor you use this:

    Date date = new Date();
    ArrayList<String> allnumbers = new ArrayList();
    Cursor c = this.getContentResolver().query(
            CallLog.Calls.CONTENT_URI,
            null,
            CallLog.Calls.TYPE + " AND " + CallLog.Calls.INCOMING_TYPE
                    + " AND " + CallLog.Calls.DATE + ">=" + date.getDate(),
            null, CallLog.Calls.NUMBER);

    allnumbers.clear();
    if (c != null)
        c.moveToFirst();
    for (int i = 0; c.getCount() > i; i++) {

        String number1 = c.getString(0);

        allnumbers.add(number1);
        c.moveToNext();

    }
    searchAndDisplay(allnumbers);

You might want to double-check that the numbers you receive is correct.

Let me know how it goes. :)

这篇关于如何让在callLog.calls最频繁的值项的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆