//一般弹窗
/* DialogInterface.OnClickListener clickListener=new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which)
{
case Dialog.BUTTON_POSITIVE:
Toast.makeText(MainActivity.this,"积极",Toast.LENGTH_SHORT).show();
break;
case Dialog.BUTTON_NEGATIVE:
Toast.makeText(MainActivity.this,"消极",Toast.LENGTH_SHORT).show();
break;
case Dialog.BUTTON_NEUTRAL:
Toast.makeText(MainActivity.this,"中立",Toast.LENGTH_SHORT).show();
break;
}
}
};
AlertDialog.Builder dialog=new AlertDialog.Builder(this);
dialog.setTitle("提示");
dialog.setMessage("这是一个提示框!");
dialog.setPositiveButton("确定",clickListener);
dialog.setNegativeButton("取消",clickListener);
dialog.setNeutralButton("忽略",clickListener);
dialog.show();*/
//列表弹窗
/* AlertDialog.Builder builder=new AlertDialog.Builder(this);
final String[] strs={"哈哈","啦啦","呜呜"};
builder.setItems(strs, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,strs[which],Toast.LENGTH_SHORT).show();
}
});
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"确定",Toast.LENGTH_SHORT).show();
}
});
builder.create().show();*/
//加载弹窗
final ProgressDialog progress=new ProgressDialog(this);
progress.setMessage("加载中。。。");
progress.setCancelable(false);//屏蔽了返回键,一定要在数据加载完毕,dismiss否则会一直存在
progress.show();
final Handler handler=new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
progress.dismiss();
}
};
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
handler.obtainMessage().sendToTarget();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
内容比较简单,就不多说了,直接看看代码就可以啦。
更多,请参考:Android之Dialog详解