<small id='Vf53E'></small><noframes id='Vf53E'>

    <legend id='Vf53E'><style id='Vf53E'><dir id='Vf53E'><q id='Vf53E'></q></dir></style></legend>

    1. <tfoot id='Vf53E'></tfoot>

      • <bdo id='Vf53E'></bdo><ul id='Vf53E'></ul>
    2. <i id='Vf53E'><tr id='Vf53E'><dt id='Vf53E'><q id='Vf53E'><span id='Vf53E'><b id='Vf53E'><form id='Vf53E'><ins id='Vf53E'></ins><ul id='Vf53E'></ul><sub id='Vf53E'></sub></form><legend id='Vf53E'></legend><bdo id='Vf53E'><pre id='Vf53E'><center id='Vf53E'></center></pre></bdo></b><th id='Vf53E'></th></span></q></dt></tr></i><div id='Vf53E'><tfoot id='Vf53E'></tfoot><dl id='Vf53E'><fieldset id='Vf53E'></fieldset></dl></div>

      Android 在 ViewPager 上方显示 SearchView 结果 ListView

      时间:2023-10-03

          • <tfoot id='ZpoTD'></tfoot>
            <i id='ZpoTD'><tr id='ZpoTD'><dt id='ZpoTD'><q id='ZpoTD'><span id='ZpoTD'><b id='ZpoTD'><form id='ZpoTD'><ins id='ZpoTD'></ins><ul id='ZpoTD'></ul><sub id='ZpoTD'></sub></form><legend id='ZpoTD'></legend><bdo id='ZpoTD'><pre id='ZpoTD'><center id='ZpoTD'></center></pre></bdo></b><th id='ZpoTD'></th></span></q></dt></tr></i><div id='ZpoTD'><tfoot id='ZpoTD'></tfoot><dl id='ZpoTD'><fieldset id='ZpoTD'></fieldset></dl></div>

              <tbody id='ZpoTD'></tbody>

            <small id='ZpoTD'></small><noframes id='ZpoTD'>

                <bdo id='ZpoTD'></bdo><ul id='ZpoTD'></ul>
                <legend id='ZpoTD'><style id='ZpoTD'><dir id='ZpoTD'><q id='ZpoTD'></q></dir></style></legend>
                本文介绍了Android 在 ViewPager 上方显示 SearchView 结果 ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                您好,我想通过 SearchView 小部件在我的应用中搜索用户.当 SearchWidget 处于活动状态时,我想在相同 XML 布局的 ViewPager 上方的 ListView 中显示建议的用户名.我使用了以下 xml

                Hi i want to search users in my app via SearchView widget. I want to show suggested users name in a ListView above a ViewPager of same XML layout when SearchWidget is active. I used following xml

                <?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" >    
                <ListView
                    android:id="@+id/searched_friends_list"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:divider="@color/list_divider"
                    android:dividerHeight="1dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:visibility="gone"
                    android:listSelector="@drawable/list_row_selector" />       
                <android.support.v4.view.ViewPager
                    android:id="@+id/pager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                </android.support.v4.view.ViewPager>
                

                并且在代码中我可见 ListView 以显示用户.

                And in code i visibled ListView to show users.

                @Override
                public boolean onQueryTextChange(String newText) {
                    friendListView.setVisibility(View.VISIBLE);
                    if (TextUtils.isEmpty(newText)) {
                        friendListView.clearTextFilter();
                    } else {
                        friendListView.setFilterText(newText.toString());
                    }
                    return true;
                }
                

                它不显示 ListView

                但是当我添加以下代码时

                but when i add following code

                @Override
                public boolean onQueryTextChange(String newText) {
                    friendListView.setVisibility(View.VISIBLE);
                    viewPager.setVisibility(View.GONE);
                    if (TextUtils.isEmpty(newText)) {
                        friendListView.clearTextFilter();
                    } else {
                        friendListView.setFilterText(newText.toString());
                    }
                    return true;
                }
                

                它显示以下输出

                但我希望 ListView 高于 ViewPager.提前致谢.

                But i want ListView above ViewPager. Thanks in advance.

                推荐答案

                如果您希望您的 ListView 实时显示用户将在 searchView 中建议的结果 - 请在您的 Adapter 中使用 Filter.

                If you want your ListView to show results in real time which user will suggest in searchView - use Filter in your Adapter.

                添加到适配器:

                ArrayList<full_data> adapterDataList = new ArrayList<full_data>();
                ArrayList<filtered_data> mFilteredDataList = new ArrayList<filtered_data>(listOR);
                Filter mFilter = new Filter() {
                @Override
                protected FilterResults performFiltering(CharSequence searchTerm) {
                Locale locale = Locale.getDefault();
                FilterResults results = new FilterResults();
                if ((searchTerm null) || (searchTerm.length() 0)) {
                ArrayList<String> searchList = new ArrayList<String>(adapterDataList);
                results.values = searchList;
                results.count = searchList.size();
                } else {
                final String searchTermString = searchTerm.toString().toLowerCase(locale);
                final String[] words = searchTermString.split(" ");
                final int wordCount = words.length;
                final ArrayList<String> newValues = new ArrayList<String>();
                
                for (final String value : adapterDataList) {
                                    if (value == null) {
                                        continue;
                                    }
                                    final String valueText = value.toLowerCase(locale);
                for (int k = 0; k < wordCount; k++) {
                                        if (valueText.contains(words[k])) {
                                            newValues.add(value);
                                            break;
                                        }
                                    }
                                }
                                results.values = newValues;
                                results.count = newValues.size();
                            }
                            return results;
                        }
                @Override
                        protected void publishResults(CharSequence constraint, FilterResults results) {
                            mFilteredDataList = (ArrayList&lt;String&gt;)results.values;
                            notifyDataSetChanged();
                        }
                    };
                public Filter getFilter(){ return mFilter; }
                
                to SearchView's TextChangedListener:
                @Override
                public void afterTextChanged(Editable searchText) {
                mAdapter.getFilter().filter(searchText);
                }
                

                我认为它应该可以正常工作.

                I think it should work fine.

                这篇关于Android 在 ViewPager 上方显示 SearchView 结果 ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:从 ViewPager 获取不同片段的值 下一篇:PagerTabStrip 中的文本未在第一个视图中显示

                相关文章

                <tfoot id='MxiDz'></tfoot>
              • <legend id='MxiDz'><style id='MxiDz'><dir id='MxiDz'><q id='MxiDz'></q></dir></style></legend>
                <i id='MxiDz'><tr id='MxiDz'><dt id='MxiDz'><q id='MxiDz'><span id='MxiDz'><b id='MxiDz'><form id='MxiDz'><ins id='MxiDz'></ins><ul id='MxiDz'></ul><sub id='MxiDz'></sub></form><legend id='MxiDz'></legend><bdo id='MxiDz'><pre id='MxiDz'><center id='MxiDz'></center></pre></bdo></b><th id='MxiDz'></th></span></q></dt></tr></i><div id='MxiDz'><tfoot id='MxiDz'></tfoot><dl id='MxiDz'><fieldset id='MxiDz'></fieldset></dl></div>

                  <small id='MxiDz'></small><noframes id='MxiDz'>

                      <bdo id='MxiDz'></bdo><ul id='MxiDz'></ul>