简体   繁体   English

单击某个项目后如何关闭回收站视图持有人?

[英]How to close recycler view holder after clicking an item?

I'm trying to close the view holder (the list of items which is shown after searching in edit text). 我正在尝试关闭视图持有者(在编辑文本中搜索后显示的项目列表)。 But I can't find the right function or way to do it! 但是我找不到合适的功能或方法! Any help? 有什么帮助吗?

I have a search adapter which I tried overriding onBindViewHolder and try to close the recycler view there. 我有一个搜索适配器,尝试覆盖onBindViewHolder并尝试在此处关闭回收站视图。 But i'm struggling with finding the right function or way.. 但是我在努力寻找正确的功能或方式。

@Override
    public void onBindViewHolder(final SearchViewHolder holder, int position) {

        holder.full_name.setText(fullNameList.get(position));
        holder.full_name.setBackgroundColor(selectedPos == position ? Color.GREEN : Color.LTGRAY);

        holder.full_name.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(final View v) {


                if (holder.getAdapterPosition() == RecyclerView.NO_POSITION) return;
                notifyItemChanged(selectedPos);
                selectedPos = holder.getLayoutPosition();
                notifyItemChanged(selectedPos);
                Toast.makeText(context, ((TextView) v).getText(), Toast.LENGTH_SHORT).show(); //Here I get the text string


                // close keyboard on click

                v.clearFocus();
                InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                        imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }



            }
        });
    }

Your question is not clear. 您的问题不清楚。 You can maybe clear the fullNameList and do a notifychange? 您也许可以清除fullNameList并执行notifychange?

@Override
    public void onClick(final View v) {
        if (holder.getAdapterPosition() == RecyclerView.NO_POSITION) return;
        notifyItemChanged(selectedPos);
        selectedPos = holder.getLayoutPosition();
        notifyItemChanged(selectedPos);
        Toast.makeText(context, ((TextView) v).getText(), Toast.LENGTH_SHORT).show(); //Here I get the text string

        //Clears the list and notify the adapter
        fullNameList.clear();
        notifyDataSetChanged();

        v.clearFocus();
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }

Although an AutoCompleteTextView should do the job just fine. 尽管AutoCompleteTextView应该可以完成这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM