public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("选项");
builder.setItems(R.array.choice, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
break;
case 1:
break;
case 2:
break;
} }
});
builder.setNegativeButton("取消", null);
builder.create().show(); }

string.xml

 <?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">AppExplorer</string>
<string name="hello_world">Hello world!</string>
<array name ="choice">
<item name="start">启动程序</item>
<item name="detail">详细信息</item>
<item name="uninstall">卸载</item>
</array>
</resources>

效果:

 public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
final PackageInfo tempPkgInfo = showPackageInfos.get(position);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("选项");
builder.setItems(R.array.choice, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0:
String packageName = tempPkgInfo.packageName;
ActivityInfo[] activityInfo = tempPkgInfo.activities;
String activityName = activityInfo[0].name;
try {
Intent i = new Intent();
i.setComponent(new ComponentName(packageName, activityName));
startActivity(i);
} catch (Exception e) {
return;
}
break;
case 1:
showAppDetail(tempPkgInfo);
break;
case 2:
Uri packageUri = Uri.parse("package:" + tempPkgInfo.packageName);
Intent deleteIntent = new Intent();
deleteIntent.setAction(Intent.ACTION_DELETE);
deleteIntent.setData(packageUri);
startActivity(deleteIntent);
break;
} } });
builder.setNegativeButton("取消", null);
builder.create().show(); }

passwordDialog = builder.create();此方法返回一个AlertDialog

AlertDialog的写法的更多相关文章

  1. Android 自定义AlertDialog的写法和弹出软键盘和覆盖状态栏

    private void showMyDialog(int layoutId){ AlertDialog myDialog = new AlertDialog.Builder(context).cre ...

  2. 【转】Android AlertDialog 点击对话框外部区域不关闭的设置

    原文网址:http://blog.sina.com.cn/s/blog_8f1c79dd0101a63u.html 在Android开发中,常常需要调用对话框,但会遇到这样一种情况,在显示对话框的时候 ...

  3. Androidbutton事件的五中写法总结

    button事件的五中写法: 1.匿名内部类 2.类实现View.OnClickListener接口 3.创建实例化接口对象 4.使用内部类 5.自己定义方法,配置Android:onclick属性 ...

  4. 安卓—自定义 AlertDialog 的样式

    自定义修改安卓弹出框的样式 效果图: 1.在style.xml下添加 <!-- 自定义弹出样式 --> <style name="MyDialogStyle" p ...

  5. obj.style.z-index的正确写法

    obj.style.z-index的正确写法 今天发现obj.style.z-index在js里面报错,后来才知道在js里应该把含"-"的字符写成驼峰式,例如obj.style.z ...

  6. java设计模式之单例模式(几种写法及比较)

    概念: Java中单例模式是一种常见的设计模式,单例模式的写法有好几种,这里主要介绍三种:懒汉式单例.饿汉式单例.登记式单例. 单例模式有以下特点: 1.单例类只能有一个实例. 2.单例类必须自己创建 ...

  7. Stack Overflow 排错翻译 - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder

    Stack Overflow 排错翻译  - Closing AlertDialog.Builder in Android -Android环境中关闭AlertDialog.Builder 转自:ht ...

  8. .NET跨平台之旅:数据库连接字符串写法引发的问题

    最近在一个ASP.NET Core站点中遇到一个奇怪问题.当用dotnet run命令启动站点后,开始的一段时间请求执行速度超慢,有时要超过20秒,有时甚至超过1分钟,日志中会记录这样的错误: Sys ...

  9. 【兼容写法】HttpServerUtility.Execute 在等待异步操作完成时被阻止。关键词:MVC,分部视图,异步

    异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html MVC6之前的版本,对分部视图的异步支持不是很好 问题: 视图里面有分布视图:@{ ...

随机推荐

  1. Java并发编程:JDK中的阻塞队列

    上次我们讲了一些常用的4个阻塞队列,但是在JDK中还提供了其他的一些阻塞队列.这篇文章将全面介绍一下JDK中的所有阻塞队列,并比较他们的区别. JDK7提供了7个阻塞队列.分别是 ArrayBlock ...

  2. Android 学习笔记之 Actionbar作为回到上一级

    首先,给Actionbar添加返回图标: 代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCrea ...

  3. C语言枚举类型(Enum)深入理解

    在实际编程中,有些数据的取值往往是有限的,只能是非常少量的整数,并且最好为每个值都取一个名字,以方便在后续代码中使用,比如一个星期只有七天,一年只有十二个月,一个班每周有六门课程等. 以每周七天为例, ...

  4. CSS 画三角形、圆

    <div class="square"></div> <style> .square { height: 0px; width: 0px; bo ...

  5. html+css底部自动固定底部

    前端在切图过程中,肯定遇见过这种情况. 页面结构由三个部分组成,头部.内容.底部. 当一个页面的内容没撑满屏幕时,底部是跟着内容而并列存在的. 这个时候如果是大屏的话,底部下面会有多余的空白区域,而网 ...

  6. cocoapods安装好后repo换源

    1.pod repo 然后会出现以下内容,如下是我已经换了之后的,而你的URL还是github的 master - Type: git (master) - URL:  https://git.cod ...

  7. SQL Server函数​---Union与Union All的区别

    SQL Server函数---Union与Union All的区别 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称 ...

  8. nginx源码编译问题

    [root@localhost nginx-1.7.4]# ./configure checking for OS + Linux 2.6.32-431.el6.x86_64 x86_64 check ...

  9. 透视I/O多路复用

    透视I/O多路复用 我写的不是select这些函数的教学,需要了解的请自行Google或者去man,这些是帮助我理解函数的封装之下的道理. 需要回答的问题 I/O准备好了指什么?什么叫I/O已经可读/ ...

  10. 【转载】32复用时钟AFIO开启情况

    原文:http://blog.csdn.net/u012411027/article/details/44217313 百度了很多结果,打开看几乎全是下面这篇文章,真是天下文章一大抄啊.我也抄一下吧. ...