1. <tfoot id='riZf3'></tfoot>
      <i id='riZf3'><tr id='riZf3'><dt id='riZf3'><q id='riZf3'><span id='riZf3'><b id='riZf3'><form id='riZf3'><ins id='riZf3'></ins><ul id='riZf3'></ul><sub id='riZf3'></sub></form><legend id='riZf3'></legend><bdo id='riZf3'><pre id='riZf3'><center id='riZf3'></center></pre></bdo></b><th id='riZf3'></th></span></q></dt></tr></i><div id='riZf3'><tfoot id='riZf3'></tfoot><dl id='riZf3'><fieldset id='riZf3'></fieldset></dl></div>

      • <bdo id='riZf3'></bdo><ul id='riZf3'></ul>

      <small id='riZf3'></small><noframes id='riZf3'>

      <legend id='riZf3'><style id='riZf3'><dir id='riZf3'><q id='riZf3'></q></dir></style></legend>

        Android 自定义列表对话框

        时间:2023-08-30
          <i id='Xyxvp'><tr id='Xyxvp'><dt id='Xyxvp'><q id='Xyxvp'><span id='Xyxvp'><b id='Xyxvp'><form id='Xyxvp'><ins id='Xyxvp'></ins><ul id='Xyxvp'></ul><sub id='Xyxvp'></sub></form><legend id='Xyxvp'></legend><bdo id='Xyxvp'><pre id='Xyxvp'><center id='Xyxvp'></center></pre></bdo></b><th id='Xyxvp'></th></span></q></dt></tr></i><div id='Xyxvp'><tfoot id='Xyxvp'></tfoot><dl id='Xyxvp'><fieldset id='Xyxvp'></fieldset></dl></div>

            <tfoot id='Xyxvp'></tfoot>
              <tbody id='Xyxvp'></tbody>

                <small id='Xyxvp'></small><noframes id='Xyxvp'>

                <legend id='Xyxvp'><style id='Xyxvp'><dir id='Xyxvp'><q id='Xyxvp'></q></dir></style></legend>
                • <bdo id='Xyxvp'></bdo><ul id='Xyxvp'></ul>
                • 本文介绍了Android 自定义列表对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述


                  我正在开发一个简单的文件浏览器应用程序.我有大部分设置(它在不同的目录中列出了一切,而且没有),但我现在被困在一起(在几个小时内工作了几个小时)是选择列表项目时,我想要出现一个自定义列表对话框.我在android开发页面上找到了这段代码并稍微修改了一下.目前它只是对所选内容进行了祝酒,但我需要将这三个项目分开.也就是说,我想做的不仅仅是祝酒,让每个选择运行不同的命令.这是我当前的代码

                  Hi,
                  I'm working on a simple file browser app. I have most of it set up (where it lists everything out in the different directories and what not) but what I'm stuck on right now (worked on it for a few hours) is when a list item is selected, I want to have a custom list dialog appear. I found this code on the android development page and modded it slightly. Currently it just gives a toast of what was selected but I need the three items to be separate. That is, I'd like to do more than a toast and have each selection run different commands. Here is my current code

                      final CharSequence[] items = {"Info", "Rename", "Delete"};
                  
                      AlertDialog.Builder builder = new AlertDialog.Builder(this);
                      builder.setTitle("Options for " + file.getName());
                      builder.setItems(items, new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int item) {
                              Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
                          }
                      }).show();
                  

                  感谢任何可以帮助我将其分开的人.我尝试了几种不同的 if 语句变体,但我尝试过的一切都失败了.

                  Thanks to anyone who can help me just separate it. I've tried a few different variations of if statements and what not but everything I've tried has failed.

                  推荐答案

                  您收到的项目整数是包含您的操作的字符序列数组的索引,因此要获取选择的操作,您可以这样做(在您的onClick 方法):

                  The item integer you receive is the index of the charsequence array that contains your actions, so to get the action that was selected you could do like this (inside your onClick method):

                  if (item == 0)
                  {
                       // Info item
                  }
                  else if (item == 1)
                  {
                       // Rename, and so one
                  

                  或者你可以这样做:

                  if (items[item].equals("Info"))
                  {
                       // Info item
                  }
                  else if (items[item].equals("Rename")
                  {
                       // Rename, and so one
                  }
                  

                  但首选第一种方法

                  这篇关于Android 自定义列表对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 Theme.Dialog 更改为 Android 中的 Theme.Light.Dialog 下一篇:优先创建 NumberPicker 对话框

                  相关文章

                  最新文章

                    <bdo id='IV2Nv'></bdo><ul id='IV2Nv'></ul>

                  1. <i id='IV2Nv'><tr id='IV2Nv'><dt id='IV2Nv'><q id='IV2Nv'><span id='IV2Nv'><b id='IV2Nv'><form id='IV2Nv'><ins id='IV2Nv'></ins><ul id='IV2Nv'></ul><sub id='IV2Nv'></sub></form><legend id='IV2Nv'></legend><bdo id='IV2Nv'><pre id='IV2Nv'><center id='IV2Nv'></center></pre></bdo></b><th id='IV2Nv'></th></span></q></dt></tr></i><div id='IV2Nv'><tfoot id='IV2Nv'></tfoot><dl id='IV2Nv'><fieldset id='IV2Nv'></fieldset></dl></div>

                  2. <tfoot id='IV2Nv'></tfoot>

                    <legend id='IV2Nv'><style id='IV2Nv'><dir id='IV2Nv'><q id='IV2Nv'></q></dir></style></legend>

                    <small id='IV2Nv'></small><noframes id='IV2Nv'>