作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
请指导我如何将条件应用于仅添加到列表中的未接来电号码的调用类型。其次热按日期排序此列表以及如何从列表中删除选定的项目。
公共(public)无效 getlog()
Cursor managedCursor = managedQuery(CallLog.Calls.CONTENT_URI, null,
null, null, null);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME)
int numberOfRows = managedCursor.getCount();
if (numberOfRows > 0) {
if (managedCursor.moveToFirst()) {
do {
String phNumber = managedCursor.getString(number);
String callType = managedCursor.getString(type);
String callDate = managedCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
String namec = managedCursor.getString(name);
if (namec == null) {
namec = "Unknown";
}
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("listview_title", namec);
hm.put("listview_number", phNumber);
hm.put("listview_date", String.valueOf(callDayTime));
hm.put("listview_image", image);
if(type == CallLog.Calls.MISSED_TYPE){ aList.add(hm);
}
while (managedCursor.moveToNext());
}
String[] from = {"listview_image", "listview_title", "listview_number", "listview_date"};
int[] to = {R.id.listview_image, R.id.listview_item_title, R.id.listview_item_number, R.id.listview_item_time};
SimpleAdapter simpleAdapter = new SimpleAdapter(getBaseContext(), aList, R.layout.custmlv, from, to);
androidListView.setAdapter(simpleAdapter);
androidListView.setOnItemLongClickListener(this);
managedCursor.close();
Collections.reverse(aList);
}
}
最佳答案
用下面的代码替换你的条件语句
String dir = null;
int dircode = Integer.parseInt(callType);
switch (dircode) {
case CallLog.Calls.OUTGOING_TYPE:
dir = "OUTGOING";
break;
case CallLog.Calls.INCOMING_TYPE:
dir = "INCOMING";
sb.append("\nPhone Number:--- " + phNumber + " \nCall Type:--- " + dir + " \nCall Date:--- " + callDayTime + " \nCall duration in sec :--- " + callDuration);
sb.append("\n----------------------------------");
miss_cal.setText(sb);
break;
case CallLog.Calls.MISSED_TYPE:
dir = "MISSED";
break;
}
您的代码的问题是您正在使用变量“type”测试条件 这是您的列名而不是列值。您应该已经检查了 callType,因为您还获得了调用类型。将 callType String 转换为 in,然后在与 CallLog.Calls.MISSED_TYPE 进行比较时进行转换: 希望对您有所帮助。
关于android - 如何仅显示通话记录android中的未接来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46542582/
我是一名优秀的程序员,十分优秀!