btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CommomDialog commomDialog = new CommomDialog(getApplicationContext(), R.style.dialog, "是否要删除门店", new CommomDialog.OnCloseListener() {
@Override
public void onClick(Dialog dialog, boolean confirm) {
Log.e(TAG, "onClick: "+confirm );
if (confirm){
Toast.makeText(getApplicationContext(),"删除",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getApplicationContext(),"取消删除",Toast.LENGTH_SHORT).show();
}
dialog.dismiss();
}
});
commomDialog.setTitle("提示").show();
}
});
原因是因为Dialog 不能用getApplicationContext(),原因是因为Token必须是Activity的Token,不然的话会抛出异常
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CommomDialog commomDialog = new CommomDialog(Test2Activity.this, R.style.dialog, "是否要删除门店", new CommomDialog.OnCloseListener() {
@Override
public void onClick(Dialog dialog, boolean confirm) {
Log.e(TAG, "onClick: "+confirm );
if (confirm){
Toast.makeText(getApplicationContext(),"删除",Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(getApplicationContext(),"取消删除",Toast.LENGTH_SHORT).show();
}
dialog.dismiss();
}
});
commomDialog.setTitle("提示").show();
}
});
网友评论