就是一个提示框er
Button dui1 = findViewById(R.id.dui1);
dui1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog alertDialog1=new AlertDialog.Builder(Alertdialog.this).create();//这里不能直接new alerdialog()他说的是因为受保护了
alertDialog1.setIcon(R.mipmap.a);
alertDialog1.setTitle("这是第一种提示框");
alertDialog1.setMessage("第一啊啊啊啊啊啊啊啊啊啊啊啊啊");
alertDialog1.setButton(DialogInterface.BUTTON_NEGATIVE, "否", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Alertdialog.this,"点击了取消按钮",Toast.LENGTH_SHORT).show();
}
});
alertDialog1.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Alertdialog.this,"点击了确定按钮",Toast.LENGTH_SHORT).show();
}
});
alertDialog1.show();
}
});
好像也没啥,但是后面的多项框的对象和这个是不一样的哦
Button dui2=findViewById(R.id.dui2);
dui2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialog2=new AlertDialog.Builder(Alertdialog.this);
alertDialog2.setIcon(R.mipmap.a);
alertDialog2.setTitle("123");
String a[]={"aaa","123","ccc","sd"};
alertDialog2.setItems(a, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(Alertdialog.this, "这是第"+which+"个", Toast.LENGTH_SHORT).show();
}
});
alertDialog2.create().show();
}
});