美文网首页
kotlin-android-extensions 在Fragm

kotlin-android-extensions 在Fragm

作者: XII01 | 来源:发表于2020-06-15 16:32 被阅读0次
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          //一定不要在这里用ID,会报空指针
            return inflater.inflate(R.layout.fragment_code, container, false)
        }
    
        override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
            super.onViewCreated(view, savedInstanceState)
           //在这里直接用id
            getCode.setOnClickListener {  }
        }
    

    如果想知道为什么请往下面看,直接上kotlin 字节码

       @Nullable
       public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          Intrinsics.checkParameterIsNotNull(inflater, "inflater");
          return inflater.inflate(layout.fragment_code, container, false);
       }
    
       public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
          Intrinsics.checkParameterIsNotNull(view, "view");
          super.onViewCreated(view, savedInstanceState);
          ((TextView)this._$_findCachedViewById(id.getCode)).setOnClickListener((OnClickListener)null.INSTANCE);
       }
    

    看kotlin源码步骤tools->kotlin->kotlin show Bytecode ->Decompile,就可以看到对应的文件

    相关文章

      网友评论

          本文标题:kotlin-android-extensions 在Fragm

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