展会信息港展会大全

Alerts 是 Android 提供的一些标准提示对话框
来源:互联网   发布日期:2015-10-03 11:30:51   浏览:2914次  

导读:在 Android 应用中使用警示框 AlertsAlerts 是 Android 提供的一些标准提示对话框1.[代码]java代码//declared as final to be able to reference it in inner class declartations of the ......

在 Android 应用中使用警示框 Alerts

Alerts 是 Android 提供的一些标准提示对话框

1. [代码]java代码

//declared as final to be able to reference it in inner class declartations of the handlers

final AlertDialog.Builder builder=new AlertDialog.Builder(this);

builder.setTitle("Alert Dialog");

builder.setMessage("This is the alert's body");

builder.setIcon(android.R.drawable.ic_dialog_alert);

builder.setPositiveButton("OK", new OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

TextView txt=(TextView)findViewById(R.id.txt);

txt.setText("You clicked Ok");

}

});

builder.setNegativeButton("Cancel", new OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

TextView txt=(TextView)findViewById(R.id.txt);

txt.setText("You clicked Cancel");

}

});

builder.setNeutralButton("Do something", new OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

TextView txt=(TextView)findViewById(R.id.txt);

txt.setText("Neutral Button Clicked");

AlertDialog ad=builder.create();

ad.cancel();

}

});

builder.setOnCancelListener(new OnCancelListener() {

@Override

public void onCancel(DialogInterface dialog) {

// TODO Auto-generated method stub

TextView txt=(TextView)findViewById(R.id.txt);

txt.setText(txt.getText()+" the cancel listner invoked");

}

});

builder.show();

2. [图片] alerts1.png

赞助本站

人工智能实验室

相关热词: Alerts 对话框

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港