如何在android中创建可编辑的下拉菜单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2243388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:08:29  来源:igfitidea点击:

how to create editable dropdown in android?

androidspinner

提问by UMAR

Can anyone help me with how to make an editable dropdown in android?

任何人都可以帮助我如何在 android 中制作可编辑的下拉菜单吗?

回答by Diego Torres Milano

If editable you should use AutoCompleteTextView.

如果可编辑,您应该使用AutoCompleteTextView

回答by Gavin

I have the same problem too. I finally tried 2 means:

我也有同样的问题。我终于尝试了两种方法:

  1. Use AutoCompleTextView, it is pretty good.

  2. Use ListPopupWindowwith a EditText. I finally used this and I wrote an article about it: http://maogm.com/blog/edittext-with-popuplist-en.html

  1. 使用AutoCompleTextView,它非常好。

  2. 使用ListPopupWindowEditText。我终于使用了这个,我写了一篇关于它的文章:http: //maogm.com/blog/edittext-with-popuplist-en.html

回答by Nonos

The accepted answer helped me except I wanted the drop down to show immediately before the user starts typing (really an editable spinner) and didn't care much about auto completetion, so I let it have the immediate drop down effect by adding:

接受的答案对我有帮助,除了我希望在用户开始输入之前立即显示下拉列表(实际上是一个可编辑的微调器)并且不太关心自动完成,所以我通过添加让它具有立即下拉效果:

autoCompleteTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                autoCompleteTextView.showDropDown();
            }
        })

In case this helps someone.

万一这对某人有帮助。

回答by Steve Haley

Have you tried reading any tutorials?

你有没有试过阅读任何教程?

For example: http://developer.android.com/guide/tutorials/views/hello-spinner.htmlhttp://www.designerandroid.com/?p=8

例如:http: //developer.android.com/guide/tutorials/views/hello-spinner.html http://www.designerandroid.com/?p=8

and so forth. Google for android spinner tutorials.

等等。Google for android spinner 教程。

回答by Dhrumil Shah

I changed the ArrayAdaptermethod of spinner and i got my custom Spinner. just change the parameter of this method like

我改变了ArrayAdapter微调器的方法,我得到了我的自定义微调器。只需更改此方法的参数,例如

Spinner spinner = (Spinner) findViewById(R.id.Spinner01);
ArrayAdapter adapter=ArrayAdapter.createFromResource(This,R.array.statename,R.layout.mylayout);
spinner.setAdapter(adp);

In Which the mylayout file contains

其中 mylayout 文件包含