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

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

  1. <tfoot id='GTdwc'></tfoot>
    <legend id='GTdwc'><style id='GTdwc'><dir id='GTdwc'><q id='GTdwc'></q></dir></style></legend>

    1. <small id='GTdwc'></small><noframes id='GTdwc'>

      在自定义对话框中设置微调器

      时间:2023-08-30

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

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

                <tbody id='LbHuS'></tbody>

              1. 本文介绍了在自定义对话框中设置微调器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我在尝试在对话框中创建 Spinner 时遇到 NullPointerException,并且似乎无法调试它,因为代码看起来很可靠.想知道其他人是否有任何想法.非常感谢任何帮助.

                I'm getting a NullPointerException while attempting to create a Spinner within a dialog and can't seem to debug it because the code looks solid. Wonder if anyone else has any idea. Any help is greatly appreciated.

                    protected Dialog onCreateDialog(int id)
                    {
                        Dialog dialog;
                        switch(id) {
                        case DIALOG_SEND_PM:
                            Spinner spinner = (Spinner)findViewById(R.id.pm_server);
                            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.server_array, android.R.layout.simple_spinner_item);
                            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                            spinner.setAdapter(adapter);
                            spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
                
                            dialog = new Dialog(PM.this);
                            dialog.setContentView(R.layout.send_pm_dialog);
                            dialog.setTitle(R.string.send_pm);
                            pmMessage = (EditText) dialog.findViewById(R.id.send_pm_box);
                            Button sendPm = (Button) dialog.findViewById(R.id.send_pm_button);
                            sendPm.setOnClickListener(PM.this);
                            break;
                        default:
                            dialog = null;
                   }
                

                我在 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);我将上下文更改为 MyClass.this 并将异常移至下一行,这让我感到困惑.我想知道它是否是具有空值的适配器,但我在不在对话框中时以与以前相同的方式调用所有内容.

                I get the exception at adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); I changed the context to MyClass.this and the exception moved down to the next line, which confuses me. I'm wondering if it is the adapter having a null value but I call everything the same way I have before while not in a dialog.

                相关的 XML 数据:

                Relevant XML data:

                <LinearLayout>
                    <TextView/>
                
                    <LinearLayout>
                
                       <TextView/>
                      <EditText/>
                      <TextView/>
                      <Spinner
                        android:id="@+id/pm_server"
                        android:layout_height="fill_parent"
                        android:layout_width="wrap_content"
                        android:background="@drawable/yblueborder"
                        android:textColor="#ABABAB"/>
                    </LinearLayout>
                
                    <Button/>
                </LinearLayout>
                

                编辑了其余的数据,以免占用太多空间.

                Edited out the rest of the data so it wouldn't take up too much space.

                推荐答案

                我已经设法解决了这个问题.这是非常微妙的,我很确定我很幸运.这是工作代码:

                I have managed to fix the issue. It was very subtle and I'm pretty sure I got lucky. Here's the working code:

                protected Dialog onCreateDialog(int id)
                    {
                        Dialog dialog;
                        switch(id) {
                        case DIALOG_SEND_PM:
                            dialog = new Dialog(PM.this);
                            dialog.setContentView(R.layout.send_pm_dialog);
                            dialog.setTitle(R.string.send_pm);
                            pmMessage = (EditText) dialog.findViewById(R.id.send_pm_box);
                            Button sendPm = (Button) dialog.findViewById(R.id.send_pm_button);
                            sendPm.setOnClickListener(PM.this);
                
                            Spinner spinner = (Spinner)dialog.findViewById(R.id.pm_server);
                            ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.server_array, android.R.layout.simple_spinner_item);
                            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                            spinner.setAdapter(adapter);
                            spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
                            break;
                        default:
                            dialog = null;
                        }
                        return dialog;
                    }
                

                我移动了一些代码,以便在微调器之前初始化对话框,但这不是问题.我添加了对话框.在 Spinner spinner = (Spinner)dialog.findViewById(R.id.pm_server);这就是诀窍.希望这对其他人有帮助.

                I moved some of the code around so that the dialog was initialized before the spinner, but that was not the issue. I added dialog. in Spinner spinner = (Spinner)dialog.findViewById(R.id.pm_server); and that did the trick. Hope this helps others.

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

                上一篇:整个对话框的Android onTouchListener 下一篇:如何更改对话框的颜色

                相关文章

                最新文章

              2. <small id='gkDwG'></small><noframes id='gkDwG'>

                  • <bdo id='gkDwG'></bdo><ul id='gkDwG'></ul>
                1. <legend id='gkDwG'><style id='gkDwG'><dir id='gkDwG'><q id='gkDwG'></q></dir></style></legend>

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

                  1. <tfoot id='gkDwG'></tfoot>