我有这个 FirebaseRecyclerAdapter:
mAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(
Chat.class,
// Below layout is where I want the AnkoComponent
android.R.layout.two_line_list_item,
ChatHolder.class,
mRef) {
@Override
public void populateViewHolder(ChatHolder chatMessageViewHolder, Chat chatMessage, int position) {
chatMessageViewHolder.setName(chatMessage.getName());
chatMessageViewHolder.setText(chatMessage.getText());
}
};
recycler.setAdapter(mAdapter);
我想使用与适配器位于不同文件中的 AnkoComponent。如果有人可以帮助我,我将不胜感激。
以防万一,下面是我想用作 viewHolder 中的列表项的 AnkoComponent。
class PriorityUI : AnkoComponent<Priority> {
override fun createView(ui: AnkoContext<Priority>) = with(ui) {
relativeLayout {
id = R.id.priority_item_layout
linearLayout {
orientation = LinearLayout.HORIZONTAL
textView {
id = R.id.textView_priority
textAlignment = Gravity.CENTER
}.lparams {
width = matchParent
}
}.lparams {
width = matchParent
}
}
}
}