string.xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tip">您好,这是我的第一个警示对话框!</string>
<string name="delete">删除</string>
<string name="app_name">AlertDialogActivity</string>
<string name="menu">这是一份菜单</string>
<string name="order">点餐</string>
</resources>
main.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/tipTextField" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/tip" />
<Button android:id="@+id/deleteButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/delete" />
</LinearLayout>
package com.baoxin.dialog;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
/**
* 警告对话框
*
* @author shyboy(897948924@qq.com)
*
*/
public class ContextMenuAlertDialog extends Activity {
private TextView menuTextView;// 声明TextView视图对象
private Button orderButton;// 声明Button按钮对象
String[] items = { "奥尔良鸡腿堡", "麻辣鸡腿堡", "咖啡" };// 设置对话框选项数组
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.menu);// 设置当前Activity的布局界面
menuTextView = (TextView) findViewById(R.id.menuTextView);// 获取TextView视图对象
orderButton = (Button) findViewById(R.id.orderButton);// 获取Button按钮对象
final Builder builder = new Builder(this);// 实例化Builder对象
/**
* 为按钮添加单击监听器
*/
orderButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
builder.setTitle("请点餐").setItems(items,
new DialogInterface.OnClickListener() {// 设置标题和选项
public void onClick(DialogInterface arg0, int arg1) {
menuTextView.setText(items[arg1]);// 设置视图文本为选中的内容
}
});
AlertDialog alertDialog = builder.create();// 创建对话框
alertDialog.show();// 显示对话框
}
});
}
}
- 描述: 运行效果图
- 大小: 9.8 KB
- 描述: 点击“点餐”按钮后的效果
- 大小: 17.3 KB
分享到:
相关推荐
Android开发中使用CRC校验,博客地址:http://blog.csdn.net/duanbokan/article/details/51282614
Android中Camera使用案例
Android中使用Shape自定义形状
可以获取系统的内存和可用内存,cpu的实时使用率
Android中文翻译组是一个非盈利性质的开源组织,聚一批开发人员、大学生、研究生等Android爱好者,利用业余时间对Android相关的API及开发者指南等进行翻译,至今已超过200人报名参与,欢迎更多朋友加入,联系Mail:...
主要内容:● 使用JNI将原生代码连接到Java中● 使用SWIG自动生成JNI代码● 使用POSIX线程实现多线程应用● 使用POSIX套接字实现网络应用● 使用logging、GDB和Eclipse调试器进行调试● 使用Valgrind分析内存● 使用...
Android中Preference的使用以及监听事件分析
Android端用itext库生成的PDF文档无法输出中文,现修改itext库jar包,未修改源码,只是加入了字体部分。调用示例亲测可用,生成中文PDF文档
1.Android中使用4.0新特性SurfaceTexture自定义相机预览 2.在PictureCallback回调中保存图片
不管你是想将已经存在的原生代码应用移植到Android平台上还是准备开始在Android平台上进行软件开发,使用《Android C++高级编程——使用NDK》一书提供的技术可以构建更出色的应用。本书将展示构建性能更好的复杂原生...
android Scroller使用小例子
Android-Idea博客:Android中如何使用ViewPager实现类似laucher左右拖动效果源码
Android中内容观察者的使用---- ContentObserver类详解
Android上自带的的wget是链接到busybox,某些需要复杂参数的下载情况不能被满足,比如需要带cookie的时候。这个版本的wget是通过wget源码编译得到的完整版本。
Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明 Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明 Android中滑屏初探 ---- scrollTo 以及 scrollBy方法使用说明
DEMO实现功能: RecyclerView的点击事件: Item及item中的子View添加点击事件 RecyclerView Item之间添加分隔线:垂直与水平方向 RecyclerView 单个与多个...LayoutManager的使用 详见http://blog.csdn.net/yalinfendou
Android播放视频的方式有三种: 一、使用意图播放,调用本地安装的播放器,选择一个进行播放。...本文章只讲解使用意图播放视频,用于处理播放的具体机制也是MediaPlayer,其余的播放将在后面的文章中讲到。
第2篇为应用开发篇,通过实例介绍了Android UI布局、Android人机界面、手机硬件设备的使用、Android本地存储系统、Android中的数据库、多线程设计、Android传感器、Android游戏开发基础、Android与Internet,以及...
博客地址 http://blog.csdn.net/sbsujjbcy/article/details/49520791
全面涵盖关于Android Studio及其庞大工具生态系统的内容,包括Git和Gradle:除了介绍Android Studio与Git(用于源代码管理)和Gradle(一款构建及测试工具)的无缝工作方式外,还演示了如何使用诸如GitHub和Bitbucket的...