2017-01-05 35 views
0

我目前正在制作一个android应用程序,用一些固定字符串数组自动完成。没有Google Places的自动完成中的当前位置?

当用户按下自动完成文本视图时,我希望打开一个带有“当前位置”选项的菜单作为默认值(在用户开始输入之前),但我没有使用Google Places(因为自动完成的值来自数组),所以我该如何做到这一点?非常感谢你!

回答

3

你想显示什么是你的AutocompleteTextView一个default suggestion

假设您有一个名为locationAutoComplete的AutocompleteTextView。 可以显示通过

locationAutoComplete.setText("current location"); 

默认建议,但存在AutocompleteTextview问题使用setText(String str)显示default suggestion;方法直接。只要调用setText(String str)方法,就会禁用AutocompleteTextView

为了防止它写下你的代码如下。

locationAutoComplete.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      locationAutoComplete.showDropDown(); 
     } 
    },500); 
    locationAutoComplete.setText("current location"); 
    locationAutoComplete.setSelection(locationAutoComplete.getText().length()); 
+0

谢谢,但我不希望它出现在文本中,我希望当用户按自动完成文本视图时,一个菜单将被打开,并且会有“当前位置”的选项。你知道怎么做吗? – user7366106

+0

我想我可以帮助你。但是请先给你机会帮助你。编辑问题并添加一些你的活动代码。然后我或任何人都能够正确地帮助你 – ash12

1

如果您只使用一组固定字符串,可以使用AutoCompleteTextView

String[] yourStrings; // However you get your strings 

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
    android.R.layout.simple_dropdown_item_1line, yourStrings); 
AutoCompleteTextView textView = (AutoCompleteTextView) 
    findViewById(R.id.your_text_view); 
textView.setAdapter(adapter); 
+0

如何在菜单中设置默认的“当前位置”选项? – user7366106

+0

您可以完全控制列表,只需将其添加到列表中。 – ianhanniballake

+0

但我希望它出现之前用户甚至开始键入任何字母 – user7366106

相关问题