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); } }

更多相关文章

  1. Android(安卓)封装实现各种样式对话框
  2. android例子源码学习
  3. Android(安卓)AlertDialog
  4. Android(安卓)上传图片到C#接口 例子
  5. android两次点击返回键退出和按钮退出对话框
  6. android数据库的简单例子
  7. Android(安卓)BaseAdapter 例子
  8. Android(安卓)RecyclerView 滑动删除例子
  9. Android双击两次返回按钮退出程序

随机推荐

  1. Android:Android涉及到的设计模式
  2. android google 分屏 多窗口 popup无法显
  3. Android尺寸单位解析
  4. Android(安卓)ashmem的实现方式
  5. 高焕堂《android从程序员到架构师之路》
  6. 彻底分清Activity的启动模式,明白什么情况
  7. Android NDk 开发简易教程
  8. Android的代码都得自己一个个敲一遍吗?
  9. 零基础Android嵌入式开发视频教程
  10. Android(安卓)自定义主题和风格