How to hide my RecyclerView

0

I have an event in my adapter that controls the click in the recyclerview items. I would like to know which code I should add when clicking the item, recycler view is hidden

@Override
public void onBindViewHolder(final SearchViewHolder holder, int position) {
        holder.titulo.setText(nomeList.get(position));
        holder.autor.setText(user_cadastroList.get(position));
        holder.setItemClickListener(new ItemClickListener() {
            @Override
            public void onClick(View view, int position, boolean isLongClick) {

CadastrarAplicacao.getUsuario().setText(nomeList.get(position).toString());

//Depois disso queria ocultar a RecyclerView

}
    
asked by anonymous 23.08.2018 / 23:45

1 answer

0

You will have to pass the click event by parameter from Activity to Adapter . on your Adapter add this interface:

public interface OnItemClickLister {
    void onItemClick(String nome);
}

In your Activity call the Adapter like this:

SeuAdapter adapter = new SeuAdapter(itens, new SeuAdapter.OnItemClickLister() {
        @Override
        public void onItemClick(String nome) {
             CadastrarAplicacao.getUsuario().setText(nomeList.get(position).toString());

             suaRecyclerView.setVisibility(View.GONE);
        }
    });

And finally in your Adapter click event, add:

holder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
    onItemClickListener.onItemClick(nomeList.get(position).toString());
}});
    
24.08.2018 / 01:33