【问题标题】:Current location in auto-complete without Google Places?在没有 Google 地方信息的情况下自动完成当前位置?
【发布时间】:2017-05-20 14:56:37
【问题描述】:

我目前正在制作一个 android 应用程序,从一些固定的字符串数组自动完成。

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

【问题讨论】:

    标签: android autocomplete location


    【解决方案1】:

    您要在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());
    

    【讨论】:

    • 谢谢,但我不希望它出现在文本中,我希望当用户按下自动完成文本视图时,会打开一个菜单并且会有一个选项的“当前位置”。你知道怎么做吗?
    • 我想我可以帮助你。但请先给机会帮助你。编辑问题并添加一些活动代码。然后我或任何人都可以正确地帮助你
    【解决方案2】:

    如果你只使用一组固定的字符串,你可以使用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);
    

    【讨论】:

    • 如何在菜单中设置默认的“当前位置”选项?
    • 您可以完全控制该列表,因此只需将其添加到您的列表中即可。
    • 但我希望它出现在用户甚至开始输入任何字母之前
    猜你喜欢
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 2015-10-03
    • 1970-01-01
    相关资源
    最近更新 更多