package com.example.dialog2;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };

Dialog alertDialog = new AlertDialog.Builder(this).
setTitle("你喜欢吃哪种水果?")
.setIcon(R.drawable.ic_launcher)

//items  和  setMessage 不能同时用
.setItems(arrayFruit, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, arrayFruit[which], Toast.LENGTH_SHORT).show();
}
}).
setNegativeButton("取消", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).
create();
alertDialog.show();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

android 带listview对话框的更多相关文章

  1. android 带CheckBox对话框

    package com.example.dialog4; import android.os.Bundle;import android.app.Activity;import android.app ...

  2. 026 Android 带不同类型条目的listview(纯文本类型的条目,图片+文字类型的条目)+读取内存空间、手机进程信息+常驻悬浮框

    1.目标效果 带不同类型条目的listview(纯文本类型的条目,图片+文字类型的条目)+常驻悬浮框 2.页面布局文件 (1)activity_process_manager.xml <?xml ...

  3. Android 利用ListView制作带竖线的多彩表格

    1.listview与GridView 其实Android本身是有表格控件(GridView)的,但是GridView的每一列的宽度被限定为一样宽,有时设计表格时,列宽不可能为同一宽度,所有可以用Li ...

  4. Android 带checkbox的listView 实现多选,全选,反选,删除

    activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  5. android 带表头,左右两个联动的ListView

    package com.rytong.mylist; import java.util.ArrayList; import java.util.HashMap; import java.util.Li ...

  6. java攻城狮之路(Android篇)--ListView与ContentProvider

    一.ListView 1.三种Adapter构建ListView ListView添加条目的时候, 可以使用setAdapter(ListAdapter)方法, 常用的ListAdapter有三种 B ...

  7. 42.Android之ListView中ArrayAdapter简单学习

    今天学习下Android中ListView关于ArrayAdapter数据绑定, 废话少说直接上代码. 改下布局文件: <?xml version="1.0" encodin ...

  8. 转--Android实现ListView过滤功能,继承于BaseAdapter,非ArrayAdapter。

    其实实现ListView过滤功能最方便的便是使用ArrayAdapter,里面自带的getFilter()方法能很方便的实现此功能,但是在实际的开发中,一般都是继承于BaseAdapter.还有一种是 ...

  9. Android:AlertDialog对话框

    1.简单的ALertDialog: Dialog alertDialog = new AlertDialog.Builder(this) .setTitle("标题") .setM ...

随机推荐

  1. Codeforces Round #265 (Div. 2)

    http://codeforces.com/contest/465 rating+7,,简直... 感人肺腑...............蒟蒻就是蒟蒻......... 被虐瞎 a:inc ARG 题 ...

  2. RabbitMQ之Exchange-4

    RabbitMQ消息模型的核心思想是生产者不会将消息直接发送给队列.生产者通常不知道消息将会被哪些消费者接收,按照刚开始里介绍的rabbitMQ中所画的,生产者不是直接将消息发送给Queue么认识会交 ...

  3. C++关键字之friend

    原则上, 类的私有(private)和受保护(protected)成员不能从声明它们的同一类外部访问.但是, 此规则不适用于友元 "friends". 以friend关键字修饰的函 ...

  4. ImageLoader must be init with configuration before using

    遇到上面的问题是没有全局初使化ImageLoader,我是在Application中配置了ImageLoaderConfiguration 解决的,当然还有官方的写法 public class MyA ...

  5. 『SharePoint 2010』Sharepoint 2010 Form 身份认证的实现(基于SQL)

    1:创建一个基于身份认证的应用程序(具体参见上篇基于AD) SQL-MembershipProvider 成员SQL-RoleManager 角色 2:修改管理中心,我们创建的应用程序,还有Web服务 ...

  6. 获取 js DOM元素中绑定的所有事件,模仿 chrome getEventListeners

    偶尔看到了这个问题,如何用JS获取元素某一事件上绑定的所有Listener? 突然觉得好像是有解决办法的,查了下,在 chrome 下,支持 window.getEventListeners(obj) ...

  7. Android开源天气预报应用Weather-Lite

    由于最近繁忙的工作告一段落,要清闲一段时间,所以可以好好利用这段时间给自己充充电. 于是乎这个app就诞生了.本着开源的精神我把它放在了github上.这里如果有Android初学者的话不妨学习一下, ...

  8. Jmeter--压测dubbo接口

    Dubbo Interface Demo:https://blog.csdn.net/qi_lin7/article/details/53759528 Demo2:https://blog.csdn. ...

  9. Python IDE软件PyCharm通用激活方法

    1,打开软件点击help-Register 2,输入地址http://xidea.online激活

  10. 2017 Multi-University Training Contest - Team 1—HDU6044

    Limited Permutation 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6044 题意:现在有一个排列p1,p2,p3,p4,p5,p6… ...