美文网首页
Java 代码的invoke

Java 代码的invoke

作者: 小磊长江大 | 来源:发表于2019-06-26 14:13 被阅读0次
    if (handlerName != null) {
                            setOnClickListener(new OnClickListener() {
                                private Method mHandler;
    
                                public void onClick(View v) {
                                    if (mHandler == null) {
                                        try {
                                            mHandler = getContext().getClass().getMethod(handlerName,
                                                    View.class);
                                        } catch (NoSuchMethodException e) {
                                            int id = getId();
                                            String idText = id == NO_ID ? "" : " with id '"
                                                    + getContext().getResources().getResourceEntryName(
                                                        id) + "'";
                                            throw new IllegalStateException("Could not find a method " +
                                                    handlerName + "(View) in the activity "
                                                    + getContext().getClass() + " for onClick handler"
                                                    + " on view " + View.this.getClass() + idText, e);
                                        }
                                    }
    
                                    try {
                                        mHandler.invoke(getContext(), View.this);
                                    } catch (IllegalAccessException e) {
                                        throw new IllegalStateException("Could not execute non "
                                                + "public method of the activity", e);
                                    } catch (InvocationTargetException e) {
                                        throw new IllegalStateException("Could not execute "
                                                + "method of the activity", e);
                                    }
                                }
                            });
                        }
    

    相关文章

      网友评论

          本文标题:Java 代码的invoke

          本文链接:https://www.haomeiwen.com/subject/ogrccctx.html