美文网首页
Android TV Leanback分析之Presenter(

Android TV Leanback分析之Presenter(

作者: Dongyp | 来源:发表于2020-03-29 16:29 被阅读0次

    Presenter是一个抽象类,和RecyclerView.Adapter中需要实现的方法相对应,onCreateViewHolder、onBindViewHolder、onUnbindViewHolder

    ViewHolder 是持有子视图的root view。其子类可扩展具体的view。

    public abstract class Presenter implements FacetProvider {
        
        //Facet用于item布局属性
        private Map<Class, Object> mFacets;
    
        public static class ViewHolder implements FacetProvider {
            public final View view;
            private Map<Class, Object> mFacets;
    
            public ViewHolder(View view) {
                this.view = view;
            }
    
        }
        public abstract ViewHolder onCreateViewHolder(ViewGroup parent);
        public abstract void onBindViewHolder(ViewHolder viewHolder, Object item);
        public abstract void onUnbindViewHolder(ViewHolder viewHolder);
        
        //...
    
    }
    

    PresenterSelector 也是一个抽象类,需要实现getPresenter

    
    public abstract class PresenterSelector {
        //子类去实现不同item获取不同Presenter
        public abstract Presenter getPresenter(Object item);
        //Presenter列表
        Presenter[] getPresenters() {
            return null;
        }
    
    }
    

    相关文章

      网友评论

          本文标题:Android TV Leanback分析之Presenter(

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