I have a constraint layout visibility that are initially set to GONE expandableLayout.setVisibility(View.GONE);
. I want to make the view to be visible when 'setOnClickListener' are issued. Then, when the user click the layout again the view will set to Gone Again.
public class ViewHolder extends RecyclerView.ViewHolder {
TextView mThicc;
ListView listView;
ConstraintLayout expandableLayout;
public ViewHolder(@NonNull View itemView) {
super(itemView);
mThicc = itemView.findViewById(R.id.thicc);
listView = itemView.findViewById(R.id.stocklist);
expandableLayout = itemView.findViewById(R.id.expandableLayout);
expandableLayout.setVisibility(View.GONE);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
expandableLayout.setVisibility(View.GONE);
}
});
}
}
The problem is, when I clicked back the layout it wont stay hidden.
Try doing conditioning and checking if view is visible or gone like this on button click
if(expandableLayout.getVisibility==View.GONE){
expandableLayout.setVisibility(View.VISIBLE);
}
else {
expandableLayout.setVisibility(View.GONE);
}