Android开发之使用活动显示对话框
2014-04-09 17:11
429 查看
利用活动显示对话框,需要重写Activity中的onCreateDialog()方法,以此来显示一个对话框窗口。
效果如下:
实现代码如下:
效果如下:
实现代码如下:
package com.example.dialog; import java.util.zip.CheckedInputStream; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Toast; public class DialogActivity extends Activity { CharSequence[] items = {"美女","世界美女","绝食美女"}; boolean[] itemsChecked = new boolean[items.length]; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); } public void onClick(View v){ showDialog(0); } @Override @Deprecated protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub switch (id) { case 0: Builder builder = new AlertDialog.Builder(this); builder.setIcon(R.drawable.ic_launcher); builder.setTitle("This is a dialog with some text"); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "OK clicked!", Toast.LENGTH_SHORT).show(); } } ); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), "Cancel clicked!", Toast.LENGTH_SHORT).show(); } } ); builder.setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface Dialog, int which, boolean isChecked) { // TODO Auto-generated method stub Toast.makeText(getBaseContext(), items[which] + (isChecked ? " Checked!":" Unchecked!" ), Toast.LENGTH_SHORT).show(); } } ); return builder.create(); } return null; } public void onClick2(View v){ final ProgressDialog progressDialog =ProgressDialog.show(this, "progressbar", "please waiting..."); new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub try { Thread.sleep(3000); progressDialog.dismiss(); } catch (InterruptedException e) { // TODO: handle exception e.printStackTrace(); } } }).start(); } }
相关文章推荐
- 【Android开发】消息提示框与对话框-使用Toast显示消息提示框
- Android 程式开发:(九)使用活动栏 —— 9.1隐藏或显示ActionBar
- Android 程式开发:(一)详解活动 —— 1.4 显示普通对话框
- 【Android开发】消息提示框与对话框-使用Notification在状态栏上显示通知
- Android开发_WebView组件使用详解_LoadUrl直接显示网页内容
- Android 程式开发:(一)详解Activity —— 1.7显示“稍微复杂”对话框
- Android开发中Dialog对话框的使用
- Android开发 使用 adb logcat 显示 Android 日志
- Android开发从入门到放弃(9)使用ListView显示一个类的数组
- Android开发本地及网络Mp3音乐播放器(十六)歌词显示及滚动事件实现、ViewPager使用
- Android开发之时间选择对话框的使用
- Android开发中使用WebView控件显示找不到网页的解决方法
- 零基础学习SDL开发之在Android使用SDL2.0显示BMP叠加图
- Android开发基础之AlertDialog的列表对话框的使用
- Android多媒体开发 音乐播放(加带进度条、时间显示)以及使用SoundPool播放音效
- Android开发第三方库glide和圆形控件circleimageview一起使用第一次进入无法显示问题
- Android 四大组件 —— 活动(使用Intent 实现活动的显示跳转)
- android 开发技巧(1)--使用 weight 属性实现视图的居中显示
- Android开发中Dialog对话框的使用
- Android使用RadioButton结合ListView显示对话框单选按钮列表