我创建了一个带有唯一键及其布尔值的哈希映射。在键中,我得到了 calllog.calls 的行唯一 ID。我想要的是那些具有相应真实值的键将从电话中的最近通话列表中删除。我需要知道如何从 calllog.calls 中查询和删除选定的行。我自己试过,但代码不起作用
public void onclickhandler(View nn){
boolean state=false;
rl=(RelativeLayout) nn.getParent();
TextView tv=(TextView)rl.getChildAt(1);
cb=(CheckBox)rl.getChildAt(2);
if(cb.isChecked()){
state=true;
}
String s=tv.getText().toString();
hmp.put(s, state);
Log.i("value", tv.getText().toString());
System.out.println(state);
} //...........
//I want to delete the contacts on button click.here
//is the code for the listener..
done.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(CallLog.Calls.CONTENT_URI,
null, null, null, null);
Set keys = hmp.keySet();
Iterator it=keys.iterator();
while (it.hasNext()) {
String keyvalue=(String) it.next();
if(hmp.get(keyvalue).booleanValue()==true){
try{
cur.moveToPosition(Integer.parseInt(keyvalue));
String lookupKey = cur.getString(cur.getColumnIndex(
CallLog.Calls.CACHED_NAME));
Uri uri = Uri.withAppendedPath(
CallLog.Calls.CONTENT_URI, lookupKey);
System.out.println("The uri is " + uri.toString());
cr.delete(uri, null, null);
}
catch(Exception e)
{
System.out.println(e.getStackTrace());
}
}//if
}//while
}//on click
});