【问题标题】:How to create dropdown list that offers cities with its first letters [closed]如何创建提供城市首字母的下拉列表[关闭]
【发布时间】:2016-04-12 22:56:55
【问题描述】:

我正在创建一个地理应用程序:我有两个用于“From”和“To”点的 editText 字段。我想这样做,当第一个字母添加到editText时,会出现下拉列表,建议城市、国家等。 例如,如果我写“新” - 纽约,新泽西,新奥尔良出现。 所以,我想要和在 Google Mapps 应用中实现的一样。

对不起,如果不清楚,我是android新手,甚至不知道如何命名。

【问题讨论】:

  • 使用 AutoCompleteTextView 。检查这个 - tutorialspoint.com/android/android_auto_complete.htm
  • 如果您可以添加一些有关您尝试过的内容的更多信息,这个问题会更好。通过在 Google 上搜索相关解决方案并在提出问题之前先试用它们,您可能会得到更好的整体服务。

标签: java android google-maps


【解决方案1】:

为此,您不能在 EditText 的 xml 中使用 AutoCompleteTextView 标记并将其传递给可能完成的数组

//Create Array Adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, languages);
//Find TextView control AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.languages);
//Set the number of characters the user must type before the drop down list is shown
acTextView.setThreshold(1);
//Set the adapter acTextView.setAdapter(adapter);

【讨论】:

  • //创建数组适配器 ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.select_dialog_singlechoice,languages); //查找TextView控件 AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.languages); //设置在下拉列表显示之前用户必须输入的字符数 acTextView.setThreshold(1); //设置适配器 acTextView.setAdapter(adapter);
  • 请将您的代码从评论移到您的答案中。带格式。谢谢
猜你喜欢
  • 1970-01-01
  • 2016-01-05
  • 2011-01-21
  • 1970-01-01
  • 2020-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多