android 确认对话框实例
package com.dialog; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; /** * 对话 确认框 例子代码 * @author CRF * */ public class exeDialogComfirm extends Activity { /** Called when the activity is first created. */ static final int DIALOG_PAUSED_ID = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout layout = new LinearLayout(this); Button button = new Button(this); button.setText("I'm So great Button"); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { showDialog(DIALOG_PAUSED_ID); } }); layout.addView(button); setContentView(layout); } @Override protected Dialog onCreateDialog(int id) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { exeDialogComfirm.this.finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); return alert; } } -------------------------------------------------------------------- 例子二:提示信息窗口例子 package com.dialog; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.Toast; /** * 点击按钮,提示信息框例子 * @author CRF * */ public class excDialog extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.main); LinearLayout layout = new LinearLayout(this); Button button = new Button(this); button.setText("I'm So great Button"); button.setOnClickListener(new OnClickListener(){ public void onClick(View v) { //提示信息显示 Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } }); layout.addView(button); setContentView(layout); } }
更多相关文章
- Android(安卓)封装实现各种样式对话框
- android例子源码学习
- Android(安卓)AlertDialog
- Android(安卓)上传图片到C#接口 例子
- android两次点击返回键退出和按钮退出对话框
- android数据库的简单例子
- Android(安卓)BaseAdapter 例子
- Android(安卓)RecyclerView 滑动删除例子
- Android双击两次返回按钮退出程序