Search in sources :

Example 1 with SimpleText

use of me.drakeet.multitype.sample.weibo.content.SimpleText in project MultiType by drakeet.

the class WeiboActivity method onCreate.

/* @formatter:on */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    RecyclerView recyclerView = findViewById(R.id.list);
    adapter = new MultiTypeAdapter();
    adapter.register(Weibo.class).to(new SimpleTextViewBinder(), new SimpleImageViewBinder()).withLinker((position, weibo) -> {
        if (weibo.content instanceof SimpleText) {
            return 0;
        } else if (weibo.content instanceof SimpleImage) {
            return 1;
        }
        return 0;
    });
    recyclerView.setAdapter(adapter);
    items = new Items();
    User user = new User("drakeet", R.mipmap.avatar);
    SimpleText simpleText = new SimpleText("A simple text Weibo: Hello World.");
    SimpleImage simpleImage = new SimpleImage(R.drawable.img_10);
    for (int i = 0; i < 20; i++) {
        items.add(new Weibo(user, simpleText));
        items.add(new Weibo(user, simpleImage));
    }
    adapter.setItems(items);
    adapter.notifyDataSetChanged();
    assertAllRegistered(adapter, items);
    loadRemoteData();
}
Also used : SimpleText(me.drakeet.multitype.sample.weibo.content.SimpleText) SimpleImageViewBinder(me.drakeet.multitype.sample.weibo.content.SimpleImageViewBinder) SimpleImage(me.drakeet.multitype.sample.weibo.content.SimpleImage) SimpleTextViewBinder(me.drakeet.multitype.sample.weibo.content.SimpleTextViewBinder) RecyclerView(android.support.v7.widget.RecyclerView) Items(me.drakeet.multitype.Items) MultiTypeAdapter(me.drakeet.multitype.MultiTypeAdapter)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 Items (me.drakeet.multitype.Items)1 MultiTypeAdapter (me.drakeet.multitype.MultiTypeAdapter)1 SimpleImage (me.drakeet.multitype.sample.weibo.content.SimpleImage)1 SimpleImageViewBinder (me.drakeet.multitype.sample.weibo.content.SimpleImageViewBinder)1 SimpleText (me.drakeet.multitype.sample.weibo.content.SimpleText)1 SimpleTextViewBinder (me.drakeet.multitype.sample.weibo.content.SimpleTextViewBinder)1