首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >隐藏Listview直到搜索启动

隐藏Listview直到搜索启动
EN

Stack Overflow用户
提问于 2015-11-17 02:30:04
回答 2查看 967关注 0票数 0

我有一个问题:我有一个列表视图(来自自定义适配器),上面有一个搜索栏。一切正常,唯一需要的是打开活动以保持列表视图隐藏或不可见,直到搜索在搜索栏中开始(换句话说,直到我开始在搜索栏中键入某些内容时,列表视图才被隐藏)。

您可以在这里找到代码:

如何在搜索过滤列表视图之后启动新的意图?

另外还有一个建议的解决方案,不幸的是,它没有起作用,您可以在这里看到:

默认情况下,Android搜索列表不可见?能办到吗?

我期待着你们的回复,伙计们,我提前感谢你们。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-11-17 04:31:10

尝试将TextWatcher添加到搜索EditText中。当您在搜索中键入某些内容时,这将检测到:

代码语言:javascript
代码运行次数:0
运行
复制
EditText search= (EditText) findViewById(R.id.search);
search.addTextChangedListener(filterTextWatcher);

TextWatcher方法:

代码语言:javascript
代码运行次数:0
运行
复制
    private TextWatcher filterTextWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) 
{
         //Change the visibility here
         list.setVisibility(View.VISIBLE);

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    };
票数 0
EN

Stack Overflow用户

发布于 2015-11-17 02:35:27

我想你可能在想一个AutoCompleteTextView?它要求您将列表数据加载到其适配器中,然后设置适配器。

代码语言:javascript
代码运行次数:0
运行
复制
// Get a reference to the AutoCompleteTextView in the layout
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// Get the string array
String[] countries = getResources().getStringArray(R.array.countries_array);
// Create the adapter and set it to the AutoCompleteTextView 
ArrayAdapter<String> adapter = 
    new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
textView.setAdapter(adapter);

谷歌指南:这里

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33748155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档