Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ImageView会一直出现在搜索界面的“我的列表项”中,即使它不应该';t安卓_Java_Android_Android Listview_Searchbar_Getview - Fatal编程技术网

Java ImageView会一直出现在搜索界面的“我的列表项”中,即使它不应该';t安卓

Java ImageView会一直出现在搜索界面的“我的列表项”中,即使它不应该';t安卓,java,android,android-listview,searchbar,getview,Java,Android,Android Listview,Searchbar,Getview,我正在制作一个应用程序,其中包含自定义ListView/GridView中的文件夹列表。在XML中,我有一个默认不可见的ImageView。在自定义ArrayAdapter类中的getView方法中,我有一个根据数据库中的值打开或关闭ImageView的方法。这可以在下面看到 @Override public View getView(int position, View convertView, ViewGroup parent){ View listItemView

我正在制作一个应用程序,其中包含自定义ListView/GridView中的文件夹列表。在XML中,我有一个默认不可见的ImageView。在自定义ArrayAdapter类中的getView方法中,我有一个根据数据库中的值打开或关闭ImageView的方法。这可以在下面看到

@Override
    public View getView(int position, View convertView, ViewGroup parent){
        View listItemView = convertView;
        if(listItemView == null){
            listItemView = LayoutInflater.from(getContext()).inflate(R.layout.folder_view, parent, false);
        }

        //getting the checkBox view id
        CheckBox checkBox = (CheckBox) listItemView.findViewById(R.id.check_box);

        checkBox.setVisibility(displayCheckBox ? View.VISIBLE : View.GONE);

        //getting the Image view id
        ImageView imageView = (ImageView) listItemView.findViewById(R.id.psw_lock);

        if(original_list.get(position).getLocked().equals("1")){
            imageView.setVisibility(View.VISIBLE);
        }else{
            imageView.setVisibility(View.INVISIBLE);
        }
但是,当我使用搜索界面搜索文件夹列表时,它可以完美地工作,直到只剩下一个结果,并且出现的列表项与imageView一起显示,即使特定项应该将可见性设置为不可见。因为这个,我不知所措

这就是问题可能出现的地方。 这是我在MainActivity中的搜索界面工具栏实现

MenuInflater inflater = getMenuInflater();
        if(whichToolbar == 0){
            //inflate menu
            inflater.inflate(R.menu.menu_search, menu);
            MenuItem searchItem = menu.findItem(R.id.search);
            SearchView searchView = (SearchView) searchItem.getActionView();
            searchView.setQueryHint("Type here to Search");

            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    setEmptyView(false);
                    itemAdapter.getFilter().filter(newText);
                    return true;
                }
            });
        }
这是位于自定义ArrayAdapter类中的覆盖过滤器方法

@NonNull
    @Override
    public Filter getFilter() {
        Filter filter = new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence charSequence) {

                //new list which contains only filtered items
                ArrayList<WordFolder> filteredList = new ArrayList<>();
                //if input in the search bar is zero/nothing
                if(charSequence == null || charSequence.length() == 0){
                    //pour the entire list in
                    filteredList.addAll(original_list);
                }
                else{
                    //lowercase the string so case doesn't matter
                    String filterPattern = charSequence.toString().toLowerCase().trim();

                    //if it contains the word/letter then add it to the filtered list
                    int i = 0;
                    for(WordFolder item : original_list){
                        if(item.getTitle().toLowerCase().contains(filterPattern)){
                            filteredList.add(item);
                        }
                    }
                }

                //make a new variable and add all of the filtered words and return it
                FilterResults results = new FilterResults();
                results.values = filteredList;
                return results;
            }

            @Override

            protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
                //clear the entire list and add it with all the filtered items
                new_list.clear();

                new_list.addAll((ArrayList<WordFolder>) filterResults.values);

                //notify the adapter that the list has changed.
                notifyDataSetChanged();

            }

        };

        return filter;
    }
@NonNull
@凌驾
公共过滤器getFilter(){
过滤器过滤器=新过滤器(){
@凌驾
受保护过滤器结果执行过滤(CharSequence CharSequence){
//仅包含筛选项的新列表
ArrayList filteredList=新建ArrayList();
//如果搜索栏中的输入为零/无
if(charSequence==null | | charSequence.length()==0){
//把整个清单都倒进去
filteredList.addAll(原始列表);
}
否则{
//将字符串小写,这样大小写就不重要了
String filterPattern=charSequence.toString().toLowerCase().trim();
//如果包含单词/字母,则将其添加到筛选列表中
int i=0;
用于(WordFolder项目:原始列表){
if(item.getTitle().toLowerCase().contains(filterPattern)){
filteredList.add(项目);
}
}
}
//创建一个新变量,添加所有过滤词并返回它
FilterResults results=新的FilterResults();
results.values=filteredList;
返回结果;
}
@凌驾
受保护的无效发布结果(CharSequence CharSequence、FilterResults FilterResults){
//清除整个列表并将其与所有筛选项目一起添加
新列表。清除();
new_list.addAll((ArrayList)filterResults.values);
//通知适配器列表已更改。
notifyDataSetChanged();
}
};
回流过滤器;
}
如果需要,我可以显示更多代码

多谢各位