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();
}
Aggregations