How to Hide My Recyclerview

Asked

Viewed 77 times

0

I have an event at my Adapter that controls the click in the items of recyclerview. I would like to know which code I should add that when clicking on the item, the Recycler view be 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

}

1 answer

0

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

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

In your Activity call the Adapter this way:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.