Search in sources :

Example 1 with HorizontalItemViewBinder

use of com.jweihao.jdemo.ui.activity.md.viewBinder.HorizontalItemViewBinder in project KL2 by jweihao.

the class RecyclerViewMultiTypeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recycler_view_multi_type);
    ButterKnife.bind(this);
    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(manager);
    mTypeAdapter = new MultiTypeAdapter();
    /* 注册类型和View的对应关系 */
    mTypeAdapter.register(Category.class, new CategoryViewBinder());
    mTypeAdapter.register(Song.class, new SongViewBinder());
    mTypeAdapter.register(PostList.class, new HorizontalItemViewBinder());
    mRecyclerView.setAdapter(mTypeAdapter);
    /* 模拟加载数据,也可以稍后再加载,然后使用
         * mTypeAdapter.notifyDataSetChanged(); 刷新列表 */
    mItems = new Items();
    List<Post> posts = new ArrayList();
    for (int i = 0; i < 30; i++) {
        mItems.add(new Category("天青色等烟雨,而我在等你。"));
        mItems.add(new Song("Android", R.drawable.ic_launcher));
        mItems.add(new Song("IOS", R.mipmap.ic_launcher_round));
        // mItems.add(new PostList(new Post(R.drawable.ic_launcher, "机器人"), 1));
        posts.add(new Post(R.mipmap.ic_launcher_round, "机器人"));
    }
    mItems.add(2, new PostList(posts));
    mTypeAdapter.setItems(mItems);
    mTypeAdapter.notifyDataSetChanged();
}
Also used : SongViewBinder(com.jweihao.jdemo.ui.activity.md.viewBinder.SongViewBinder) Category(com.jweihao.jdemo.bean.Category) CategoryViewBinder(com.jweihao.jdemo.ui.activity.md.viewBinder.CategoryViewBinder) HorizontalItemViewBinder(com.jweihao.jdemo.ui.activity.md.viewBinder.HorizontalItemViewBinder) Post(com.jweihao.jdemo.bean.Post) ArrayList(java.util.ArrayList) PostList(com.jweihao.jdemo.bean.PostList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Song(com.jweihao.jdemo.bean.Song) Items(me.drakeet.multitype.Items) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 Category (com.jweihao.jdemo.bean.Category)1 Post (com.jweihao.jdemo.bean.Post)1 PostList (com.jweihao.jdemo.bean.PostList)1 Song (com.jweihao.jdemo.bean.Song)1 CategoryViewBinder (com.jweihao.jdemo.ui.activity.md.viewBinder.CategoryViewBinder)1 HorizontalItemViewBinder (com.jweihao.jdemo.ui.activity.md.viewBinder.HorizontalItemViewBinder)1 SongViewBinder (com.jweihao.jdemo.ui.activity.md.viewBinder.SongViewBinder)1 ArrayList (java.util.ArrayList)1 Items (me.drakeet.multitype.Items)1 MultiTypeAdapter (me.drakeet.multitype.MultiTypeAdapter)1