florent37 / ExpansionPanel

Android - Expansion panels contain creation flows and allow lightweight editing of an element.
https://material.io/guidelines/components/expansion-panels.html
Apache License 2.0
1.98k stars 240 forks source link

toggle() does not work #33

Closed penpens closed 5 years ago

penpens commented 6 years ago

Hi I'm trying to toggle the layout from code, but it does not work.

Calling toggle() (not expanding): immagine

Pressing on the header (and works fine): immagine2

My code:

public void addDynamicLayout(int count_p, String[] param) {
        final String nome = "PROGRAMMA " + String.valueOf(count_p);
        final ExpansionHeader expansionHeader = createExpansionHeader(count_p, nome);
        dynamicLayoutContainer.addView(expansionHeader, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        final ExpansionLayout expansionLayout = createExpansionLayout(count_p, param);
        dynamicLayoutContainer.addView(expansionLayout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        expansionLayout.addListener(new ExpansionLayout.Listener() {
            @Override
            public void onExpansionChanged(ExpansionLayout expansionLayout, boolean expanded) {
                editorProg.putBoolean(nome, expansionHeader.isExpanded());
                editorProg.commit();
            }
        });

        boolean toggle = toggleProg.getBoolean(nome, false);

        if (toggle) {
            expansionLayout.toggle(true);
        }

        expansionHeader.setExpansionLayout(expansionLayout);
    }

Thanks in advance.

florent37 commented 5 years ago

Try to change the position of the last Line ''header.setLayout''

Le mar. 18 sept. 2018 à 09:17, penpens notifications@github.com a écrit :

Please, I need this function...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/florent37/ExpansionPanel/issues/33#issuecomment-422282215, or mute the thread https://github.com/notifications/unsubscribe-auth/AFfQXKp7N7Qhj-dD8N89QNJY_178BIGTks5ucJ4ngaJpZM4VX8uq .

penpens commented 5 years ago

Not working. At the end, finally, I made an working workaround using performClick(). Anyway, thanks for the help.

findViewById(R.id.lay_sms).findViewWithTag("headerProg1").post(new Runnable() {
                            @Override
                            public void run() {
                                findViewById(R.id.lay_sms).findViewWithTag("headerProg1").performClick();
                            }
                        });