安卓AlertDialog 的使用
引入空间
import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity;
- final AlertDialog dia;
.setMessage("你好啊,第一次来这里吗?")
.setIcon(R.mipmap.ic_launcher)
.setPositiveButton("是的", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("不是",null)
.setNeutralButton("不告诉你",null)
.create();
dia.show()
2. class vclick implements View.OnClickListener
{ @Override public void onClick(View v) { switch ( v.getId()) { case R.id.center: AlertDialog.Builder alert=new AlertDialog.Builder(MainActivity.this); alert.setIcon(R.mipmap.ic_launcher); alert.setTitle("希望你好好的但是我还是要问问的!"); alert.setMessage("你好吗?"); alert.setPositiveButton("好啊",new dclick()); alert.setNegativeButton("不好",new dclick()); alert.setNeutralButton("还行",new dclick()); alert.show(); break; case R.id.b2: AlertDialog.Builder listalert=new AlertDialog.Builder(MainActivity.this); String [] s={"我是谁?","我为什么在这个世界?","有什么意义?"}; listalert.setIcon(R.mipmap.ic_launcher); listalert.setTitle("你希望我回答你什么问题呐?"); listalert.setItems(s,new dclick()); listalert.show(); break; } } }
3
class dclick implements DialogInterface.OnClickListener { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: Toast.makeText(MainActivity.this,"开心就好!哈哈哈,你开心我也开心!",Toast.LENGTH_SHORT).show(); break; case DialogInterface.BUTTON_NEGATIVE: Toast.makeText(MainActivity.this,"不开心吗?那可不行啊,你有我哪,你桑心我陪你桑心!",Toast.LENGTH_SHORT).show(); break; case DialogInterface.BUTTON_NEUTRAL: Toast.makeText(MainActivity.this,"那可不行啊,人生潇洒是一场,悲桑也是一场,怎么可以随随便便,开心点啊!",Toast.LENGTH_SHORT).show(); break; case 0: Toast.makeText(MainActivity.this,"我可不管反正我就喜欢你!",Toast.LENGTH_SHORT).show(); break; case 1: Toast.makeText(MainActivity.this,"因为爱这个世界啊",Toast.LENGTH_SHORT).show(); break; case 2: Toast.makeText(MainActivity.this,"活着就是有意义",Toast.LENGTH_SHORT).show(); break; } } }