作家
登录

Android Study之findViewById变迁之路

作者: 来源: 2017-07-03 10:58:57 阅读 我要评论

to use in data binding. 
  •      * @param activity The Activity whose content View should change. 
  •      * @param layoutId The resource ID of the layout to be inflated, bound, and set as the 
  •      *                 Activity's content. 
  •      * @return The binding associated with the inflated content view
  •      */ 
  •     public static <T extends ViewDataBinding> T setContentView(Activity activity, int layoutId, 
  •             DataBindingComponent bindingComponent) {        // 设置ContentView 
  •         activity.setContentView(layoutId);        // 获取View实例 
  •         View decorView = activity.getWindow().getDecorView();        // 查找内容 
  •         ViewGroup contentView = (ViewGroup) decorView.findViewById(android.R.id.content);        // 返回绑定后添加的View 
  •         return bindToAddedViews(bindingComponent, contentView, 0, layoutId); 
  •     }  
  • 3.最后我们会发明他经由过程校验节点数量去绑定并添加View返回


    1. // 办法名键明其意 绑定并添加到View 
    2.     private static <T extends ViewDataBinding> T bindToAddedViews(DataBindingComponent component, 
    3.             ViewGroup parent, int startChildren, int layoutId) {        // 获取到parent下子节点数量 
    4.         final int endChildren = parent.getChildCount();        // 校验其下节点数量 
    5.         final int childrenAdded = endChildren - startChildren;        if (childrenAdded == 1) { // 如不雅只有一个节点,获取实例并添加绑定返回即可 
    6.             final View childView = parent.getChildAt(endChildren - 1);            return bind(component, childView, layoutId); 
    7.         } else

        推荐阅读

        郑州,为智慧城市升级提供模板

      产学研一体化,催生聪明应用模式 &ldquo;郑州大年夜六、七年前就开端做数字城市,然则它的数据信息是静止的,二维的。和数字城市比拟,聪明城市请求是可测量、可感知、可分析、可视化的,也>>>详细阅读


      本文标题:Android Study之findViewById变迁之路

      地址:http://www.17bianji.com/lsqh/35987.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)