Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

反射是可以调用到"setOnCheckedChangeWidgetListener"这个父类私有隐藏方法的。 #1

Open
lijunhuayc opened this issue Jan 17, 2019 · 0 comments

Comments

@lijunhuayc
Copy link

lijunhuayc commented Jan 17, 2019

            Method[] methods = child.getClass().getSuperclass().getDeclaredMethods();
            Method targetMethod = null;
            for (Method method : methods) {
                method.setAccessible(true);
                if (method.getName().equals("setOnCheckedChangeWidgetListener")) {
                    targetMethod = method;
                    break;
                }
            }
            try {
                if (targetMethod != null) {
                    targetMethod.invoke(child, mChildOnCheckedChangeListener);
                }
            } catch (Exception pE) {
                pE.printStackTrace();
            }

还请以这种方式调整一下View的逻辑。

        group.setOnCheckedChangeListener(new FlexRadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(@IdRes int checkedId) {
                mProtectFromCheckedChange = true;
            }
        });
        rb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mProtectFromCheckedChange && ((RadioButton) v).isChecked()) {
                    group.clearCheck();
                } else mProtectFromCheckedChange = false;
            }
        });

这种使用方式封装性不够。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant