|
btnShowDialog_Layout=(Button)this.findViewById(R.id.Button02);
btnShowDialog_Layout.setOnClickListener(new ClickEvent());
//统一处理按键事件
class ClickEvent implements OnClickListener{
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==btnShowDialog)
showDialog(testAlertDialog.this);
else if(v==btnShowDialog_Layout)
showDialog_Layout(testAlertDialog.this);
}
}
private void showDialog_Layout(Context context) {
LayoutInflater inflater = LayoutInflater.from(this);
final View textEntryView = inflater.inflate(
R.layout.dialoglayout, null);
final EditText edtInput=(EditText)textEntryView.findViewById(R.id.edtInput);
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
if(!builder.create().iSSHowing()){
builder.setCancelable(false);//设置back键是否可以取消
builder.setIcon(R.drawable.icon);
builder.setTitle("Title");
builder.setView(textEntryView);
builder.setPositiveButton("确认",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setTitle(edtInput.getText());
}
});
builder.setNegativeButton("取消",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setTitle("");
}
});
builder.show();
}
}
发现点击快的时候,按钮事件会触发多次,弹出多个对话窗口。请教如何处理? |
|