ExpandableCardView icon indicating copy to clipboard operation
ExpandableCardView copied to clipboard

expand and collapse problem

Open JavaDeveloper08 opened this issue 5 years ago • 4 comments

Hi, I have 2 cardviews. If I click the first card view, I would like to expand this card view and to collapse the second card view. By the same way, if I click the second card view, I would like to expand this card view and to collapse the first card view,

Unfortunately, the card view that I want to collapse is disappearing from the screen. and it is not reachable again. please help me for solving this problem.

card1 = root.findViewById(R.id.x1); card2 = root.findViewById(R.id.x2);

    card1.setOnExpandedListener(new ExpandableCardView.OnExpandedListener() {
        @Override
        public void onExpandChanged(View v, boolean isExpanded) {
            
            if (isExpanded)
                card2.collapse();
        }
    });

    card2.setOnExpandedListener(new ExpandableCardView.OnExpandedListener() {
        @Override
        public void onExpandChanged(View v, boolean isExpanded) {
            
            if(isExpanded)
                card1.collapse();

        }
    });

JavaDeveloper08 avatar Sep 13 '19 11:09 JavaDeveloper08

I have the same problem. Is this issue solved?

princeivankent avatar May 19 '20 03:05 princeivankent

Hi @princeivankent, I solved this problem. You need to expand cardviews by giving a delay at first. I am adding code below.

private void cardViewListeners() {

    try {

        new Handler().postDelayed(() -> binding.cardView1.expand(), 100);

        new Handler().postDelayed(() -> binding.cardView2.expand(), 100);

        binding.cardView1.setOnExpandedListener((v, isExpanded) -> {

            if (isExpanded) {
                new Handler().postDelayed(() -> {
                    binding.cardView2.collapse();
                }, 100);
            }
        });

        binding.cardView2.setOnExpandedListener((v, isExpanded) -> {

            if (isExpanded) {
                new Handler().postDelayed(() -> {
                    binding.cardView1.collapse();
                }, 30);
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

JavaDeveloper08 avatar May 19 '20 14:05 JavaDeveloper08

handed this, check the card is expanded before the collapse

             if (card2.isExpanded) {
                 card2.collapse()
             }`

Anilugale avatar Mar 01 '21 13:03 Anilugale

I'm having same problem

shahzad1 avatar Mar 03 '21 06:03 shahzad1