解决方案 »

  1.   

    我就不跟你说原理了, 你可以自己去探究,我告诉你问题所在的原因:
    1.在使用Fragment的时候,所有监听事件,都必须find出来,并且setonClicklistener
    2.如:该Fragment实现OnClickListener接口,在onViewCreated方法中
    view.findViewById(R.id.button1).setOnClickListener(this);
    接下来的OnClick就生效了
      

  2.   

    你的selftDestruct(View view)这个方法应该要写在加载这个view的activity的类里面
    参考view初始化的代码View.java                case R.styleable.View_onClick:
                        if (context.isRestricted()) {
                            throw new IllegalStateException("The android:onClick attribute cannot "
                                    + "be used within a restricted context");
                        }                    final String handlerName = a.getString(attr);
                        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);
                                    }
                                }
                            });
                        }
                        break;
      

  3.   

    应该是1楼的说法,fragment不能像activity那样直接写事件