• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ゞ繌瓜oо
博客园    首页    新随笔    联系   管理    订阅  订阅

列表项对话框

启动一个列表项对话框,如图所示: 

                     

代码实现的片断如下所示:    

return new AlertDialog.Builder(AlertDialogSamples.this)

        .setTitle(R.string.select_dialog)

        .setItems(R.array.select_dialog_items, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                String[] items =  getResources().getStringArray(R.array.select_dialog_items);

                new AlertDialog.Builder(AlertDialogSamples.this)

                        .setMessage("You selected: " + which + " , " + items[which])

                        .show();

            }

        })

这里使用了setItems()表示设置几个不同的项目,从res/values/array.xml文件中取得select_dialog_items的内容,这部分内容如下所示:

<string-array name="select_dialog_items">

        <item>Command one</item>

        <item>Command two</item>

        <item>Command three</item>

        <item>Command four</item>

    </string-array>

 这里的Item也设置了点击函数,因此它们被点击后,也会弹出新的对话框。 

posted @ 2013-06-17 22:35  只爱、娜女孩  阅读(145)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3