Android中用两层AlertDialog来进行弹出选择框信息选择
2012-01-06 19:51
459 查看
在Android经常会用到AlertDialog,把内容使用AlertDialog结合列表的形式显示出来,然后我们点击得到点击的信息。 这里可以使用两层的AlertDialog来实现
1:我们现在xml文件中定义一个要显示内容列表数组
2:在Activity中使用 String[] items = getResources().getStringArray(R.array.item);
3:增添点击事件,使用Alertdialog.builder 千万不能忘了最后进行show()哦
直接看截图的效果:
源代码:
string.xml文件内容:
1:我们现在xml文件中定义一个要显示内容列表数组
2:在Activity中使用 String[] items = getResources().getStringArray(R.array.item);
3:增添点击事件,使用Alertdialog.builder 千万不能忘了最后进行show()哦
直接看截图的效果:
源代码:
package com.jiangqq.alertdialog; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; /** * 使用AlertDialog进行选择功能 * * @author jiangqq * */ public class AlertDialogActivity extends Activity { private Button btn; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { final String[] items = getResources().getStringArray( R.array.item); new AlertDialog.Builder(AlertDialogActivity.this) .setTitle("请点击选择") .setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { new AlertDialog.Builder( AlertDialogActivity.this) .setTitle("你选择了:" + items[which]) .setMessage("点击选择操作") .setPositiveButton( "确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { // 这里是你点击确定之后可以进行的操作 } }) .setNegativeButton( "取消", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int which) { // 这里点击取消之后可以进行的操作 } }).show(); } }).show(); } }); } }
string.xml文件内容:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, AlertDialogActivity!</string> <string name="app_name">Hello World, AlertDialogActivity</string> <string name="btn_name">点击弹出AlertDialog</string> <string-array name="item"> <item>第一个选择</item> <item>第二个选择</item> <item>第三个选择</item> <item>第四个选择</item> </string-array> </resources>
相关文章推荐
- Android中用两层AlertDialog来进行弹出选择框信息选择
- Android中用两层AlertDialog来进行弹出选择框信息选择
- Android弹出提示框数据进行选择
- Android 崩溃异常时弹出Dialog让用户选择是否上传错误信息
- android 输入首字符,提示信息,并进行选择显示在搜索框
- android App一段时间没有操作或没有点击屏幕后弹出广告,或者一段时间没有点击屏幕进行特定操作。
- [Unity]Android(安卓)代码安卓APK时,使用系统安装器安装的[最正确]办法(不弹出选择打开的程序)
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- Android AlertDialog 动态更新弹出框中的内容
- java android 对一个集合进行连续有选择的删除
- Android调用系统自带的文件管理器进行文件选择并获得路径,android文件管理器
- Android 限制只调用系统相机 不弹出应用选择器
- 用信息值进行特征选择(Information Value)
- android之具有选择功能的AlertDialog
- android调用系统相机拍照与打开相册选择照片进行截取保存笔记
- Android控件之AlertDialog-单选、多选信息列表弹出框
- 用于弹出ModalDialog进行数据选择的控件
- 4000 android 有确认和取消按钮的 AlertDialog 弹出的使用说明
- android 我用过的一些权限,网络、SD卡、手机硬件信息、自动横屏、键盘自动弹出
- web 弹出框 类似 android的toast的信息提示