增加和删除黑名单号码
技术点:1、alertDialog.dismiss()和alertDialog.cancel()区别 没有什么太大区别,只是cancel()会发送一个消息,可以通过OnCancelListener()进行接收 Cancel the dialog. This is essentially the same as calling dismiss() ,
but it will also call your DialogInterface.OnCancelListener
(if registered). |
2、Android下点击事件响应的顺序 |
3、添加黑名单号码 /**
* 1、添加黑名单
* @param view
*/
public void add_blacklist(View view){
AlertDialog.Builder builder = new Builder(this);
View myView = View.inflate(this, R.layout.dialog_add_blacknumber_callsmssafe, null);
Button bt_ok = (Button) myView.findViewById(R.id.bt_callsmssafe_ok);
Button bt_cancel = (Button) myView.findViewById(R.id.bt_callsmssafe_cancel);
final EditText et_number = (EditText) myView.findViewById(R.id.et_blacknumber);
final RadioGroup rg_mode = (RadioGroup) myView.findViewById(R.id.rg_blacknumber_mode);
final AlertDialog alertDialog = builder.create();
alertDialog.setView(myView, 0, 0, 0, 0);
// 添加
bt_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "添加一条黑名单记录到数据库中~~~");
String blacknumber = et_number.getText().toString().trim();
if (TextUtils.isEmpty(blacknumber)) {// 黑名单号码是否为null
ToastUtils.showToastInThread(CallSmsSafeActivity.this, "号码不能为null~~~");
return;
}
if (blackNumberDao.find(blacknumber)) {// 数据库中是否已经存在了此黑名单号码
ToastUtils.showToastInThread(CallSmsSafeActivity.this, "数据库中已经存在此黑名单号码~~~");
return;
}
int checkedRadioButtonId = rg_mode.getCheckedRadioButtonId();
String blacknumber_mode = "3";// 默认拦截短信和电话号码
switch (checkedRadioButtonId) {
case R.id.rb_phone:// 2
blacknumber_mode = "2";
break;
case R.id.rb_sms:// 1
blacknumber_mode = "1";
break;
case R.id.rb_all:// 3
blacknumber_mode = "3";
break;
}
blackNumberDao.add(blacknumber, blacknumber_mode);//添加到数据库
blackNumberInfos.add(0, new BlackNumberInfo(0,blacknumber,blacknumber_mode));//添加到集合中,可以立即在界面上最上面显示出来
callSmsSafeAdapter.notifyDataSetChanged();// 刷新listview中的数据
alertDialog.dismiss();
}
});
// 取消
bt_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.dismiss();
}
});
alertDialog.show();
} |
4、删除黑名单数据 // 6、注册黑名单删除事件
viewHolder.iv_image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, "删除黑名单:" + blackNumberInfo.getNumber());
blackNumberDao.delete(blackNumberInfo.getNumber());// 删除点击的item
blackNumberInfos.remove(position);// 从集合中给删除
callSmsSafeAdapter.notifyDataSetChanged();// 更新界面
// FIXME :来一个用户确认删除的对话框,防止用户误删除
}
});
|