0

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



            }
        });
    }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

Your question is not clear. You can maybe clear the fullNameList and do a 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.

Vebito
  • 154
  • 1
  • 10