80,351
社区成员
发帖
与我相关
我的任务
分享
listView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
SmsThreadBean cb = (SmsThreadBean) arg0.getItemAtPosition(arg2); //thread_id=193, date=1409294307158, snippet=【碧欧泉】对抗岁月侵袭,夜间也需专属呵护?全新碧欧泉蓝源夜间精油凝露9/1重磅上市!融合精油滋养力+精华渗透性,首创夜间精油凝露,数量有限,赠完即止!回TD退订, phoneNums=[10690029619532], contactNames=[null], message_count=1
SMSBean smsb = new SMSBean(); //短信内容的bean
smsb.setThread_id(cb.thread_id + "");
smsb.setContact_name(cb.contactNames[0]);
smsb.setAddress(cb.phoneNums[0]);
// smsb:thread_id=193, msg_count=null, msg_snippet=null, address=10690029619532, contact_name=null, date=null, read=null
if (smsb.getContact_name() == null|| "".equals(smsb.getContact_name())) {
smsb.setContact_name(cb.phoneNums[0]);
//thread_id=193, msg_count=null, msg_snippet=null, address=10690029619532, contact_name=10690029619532, date=null, read=null
}
showContactDialog(lianxiren1, smsb, arg2);
return false;
}
});
private String[] lianxiren1 = new String[] { "删除" };
private void showContactDialog(final String[] arg, final SMSBean sms,
final int position) {
new AlertDialog.Builder(this).setTitle(sms.getContact_name()).setItems(arg, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
long id = Long.valueOf(sms.getThread_id()); //193
Uri uri = Uri.parse("content://sms/conversations/" + id); //content://sms/conversations/193
int length = context.getContentResolver().delete(uri,null, null); //0
if (length!= 0) {
queryMsgs();
}
adapter.notifyDataSetChanged();
}
}).show();