【问题标题】:Hiding Listview until search is initiated隐藏 Listview 直到搜索开始
【发布时间】:2015-11-17 02:30:04
【问题描述】:

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

你可以在这里找到代码:

How to start new intent after search-filtering listview?

加上一个建议的解决方案,不幸的是没有奏效,你可以在这里看到:

Android search list invisible by default? Can it be done?

期待你们的回复,提前谢谢你们。

【问题讨论】:

    标签: android listview search android-listview hidden


    【解决方案1】:

    尝试将TextWatcher 添加到您的搜索EditText。这将检测您何时在搜索中输入内容:

    EditText search= (EditText) findViewById(R.id.search);
    search.addTextChangedListener(filterTextWatcher);
    

    TextWatcher 方法:

        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) {
    
            }
        };
    

    【讨论】:

      【解决方案2】:

      我认为您可能正在考虑使用 AutoCompleteTextView?它要求您将列表数据加载到其适配器中,然后设置适配器。

      // 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);
      

      Google 指南:here

      【讨论】:

      • 嗨弗兰克,我对搜索活动没有任何问题。我想要的只是当我打开列表视图所在的活动时(即 Activity_Main)以保持列表视图隐藏/不可见,直到我开始搜索某些东西......
      • 所以你想要一个全屏版本的 AutoCompleteTextView?
      • 没有。我只想让我的列表视图不可见;-)
      • 对不起,我不确定您在寻找什么样的行动。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多