先来看清空号码操作(第一个选项是清空所有、下面的是popupwindow动态填充电话号码。为清空单个号码通话记录)
/** 查询到单个号码的Sipaccount*/
if (mContactDailDetailAdapter != null) {
String currSipaccount = phoneList
.get(position - 1)
.getSipaccount();
/**从ui界面清楚该号码记录*/
mContactDailDetailAdapter
.deleVoipCall(
currSipaccount,
contactId);
try {
/**从数据库中删除*/
SQLiteManager
.getInstance()
.deleteUserVoipCallsByContactID(
contactId,
currSipaccount);
CASApplication
.getInstance()
.sendBroadcast(
CASIntent.ACTION_CALL_LOG_INIT);
} catch (ContactsException e) {
e.printStackTrace();
}
/**最后刷新ui界面*/
mContactDailDetailAdapter
.notifyDataSetChanged();
}
然后看adapter里面怎样对清空进行操作的
/**清空单个号码的通话记录*/
public void deleVoipCall(String currSipaccount, long contactId) {
if (currSipaccount != null) {
List<CallsListItem> singlePhoneVoipCalls = null;
try {
/**从数据库中查询单个号码的通话记录。而且创建暂时的list集合*/
singlePhoneVoipCalls = SQLiteManager.getInstance()
.getUserVoipCallsByContactId(contactId, currSipaccount,
System.currentTimeMillis() + "",
Integer.MAX_VALUE);
} catch (ContactsException e) {
e.printStackTrace();
}
/**推断非空进行操作。直接从展现ui界面的data数据中移除调就可以*/
if (singlePhoneVoipCalls != null) {
if (userVoipCalls!=null) {
userVoipCalls.removeAll(singlePhoneVoipCalls);
}
}
} else {
Toast.makeText(context, "非国鼎注冊账号,暂无通话记录", 0).show();
}
}
/**点击popup第一项调用的方法。直接clear数据集合*/
public void deleAllVoipCall() {
if (userVoipCalls!=null) {
userVoipCalls.clear();
}
}
--------------------------------------接下来看查询操作---------------------------------------
if (position == 0) {
/**查看某个联系人下的所以号码的通话记录*/
if (mContactDailDetailAdapter != null) {
/**从adapter里面进行操作*/
mContactDailDetailAdapter.queryAllVoipCall(contactId);
mContactDailDetailAdapter.notifyDataSetChanged();
} else {
Toast.makeText(ContactDailDetailActivity.this,
"通话记录列表为空", 0).show();
}
} else {
// position大于0时
if (mContactDailDetailAdapter != null) {
if (phoneList != null && phoneList.size() > 0) {
String currSipaccount = phoneList.get(position - 1)
.getSipaccount();
if (currSipaccount != null) {
mContactDailDetailAdapter.queryVoipCall(
contactId, currSipaccount);
mContactDailDetailAdapter
.notifyDataSetChanged();
} else {
/**假设不是正常号码,就直接清空ui界面*/
mContactDailDetailAdapter.deleAllVoipCall();
mContactDailDetailAdapter
.notifyDataSetChanged();
}
}
}
}
接下来看adapter里面的查询方法操作
public class ContactDailDetailAdapter extends BaseAdapter {
private List<Phone> phoneList;
private Context context;
private List<CallsListItem> userVoipCalls= new ArrayList<CallsListItem>();
public static int pos = -1;
private SlideListView mListView;
public ContactDailDetailAdapter(List<Phone> phoneList, Context context,
List<CallsListItem> userVoipCalls) {
this.phoneList = phoneList;
this.context = context;
this.userVoipCalls = userVoipCalls;
}
/**查询某联系人全部号码的通话记录*/
public void queryAllVoipCall(long contactId) {
try {
/**从数据库中获取该联系人全部号码的全部通话记录,并创建暂时的通话记录集合*/
List<CallsListItem> temp=SQLiteManager.getInstance().getUserVoipCallsByContactId(contactId,
null, System.currentTimeMillis() + "",
Integer.MAX_VALUE);
//推断非空并清空展示ui界面的data数据集合
if (userVoipCalls!=null) {
userVoipCalls.clear();
}
//推断非空。而且将暂时的记录加入到data数据集合
if(temp != null)
{
userVoipCalls.addAll(temp);
}
} catch (ContactsException e) {
e.printStackTrace();
}
}
// 查看号码的通话记录--同查询全部号码的通话记录方法一样
public void queryVoipCall(long contactId,String currSipaccount) {
if (currSipaccount != null) {
try {
List<CallsListItem> temp=SQLiteManager.getInstance().getUserVoipCallsByContactId(contactId,
currSipaccount, System.currentTimeMillis() + "",
Integer.MAX_VALUE);
if (userVoipCalls!=null) {
userVoipCalls.clear();
}
if(temp != null)
{
userVoipCalls.addAll(temp);
}
} catch (ContactsException e) {
e.printStackTrace();
}
}
}