在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):AllenCoder/BRVAH_kotlin开源软件地址(OpenSource Url):https://github.com/AllenCoder/BRVAH_kotlin开源编程语言(OpenSource Language):Kotlin 97.1%开源软件介绍(OpenSource Introduction):This is the Kotlin version of BaseRecyclerViewAdapterHelper using DemoBaseRecyclerViewAdapterHelper中文参考文档A powerful and flexible RecyclerViewAdapter is welcome to use. (Like you can Star ) Download apk)What can it do?(
How do you use it?First add the repositories in build.gradle::
Then add in the dependencies:
How do you use it to create an adapter?class QuickAdapter(dataSize: Int) : BaseQuickAdapter<Status, BaseViewHolder>(R.layout.layout_animation, DataServer.getSampleData(dataSize)) {
override fun convert(helper: BaseViewHolder, item: Status) {
when (helper.layoutPosition % 3) {
0 -> helper.setImageResource(R.id.img, R.mipmap.animation_img1)
1 -> helper.setImageResource(R.id.img, R.mipmap.animation_img2)
2 -> helper.setImageResource(R.id.img, R.mipmap.animation_img3)
}
helper.setText(R.id.tweetName, "Hoteis in Rio de Janeiro")
helper.setText(R.id.tweetText, "O ever youthful,O ever weeping")
}
} Adapter adapter.onItemClickListener = BaseQuickAdapter.OnItemClickListener { adapter, view, position ->
Log.d(TAG, "onItemClick: ")
Toast.makeText(this@ItemClickActivity, "onItemClick" + position, Toast.LENGTH_SHORT).show()
}
Set the item click to add a click event that adds multiple controls to multiple controlsSet it item child clickFirst you need to add the childview id that you want to click on
Activity mAnimationAdapter.onItemChildClickListener = BaseQuickAdapter.OnItemChildClickListener { adapter, view, position ->
var content: String
val status = adapter.getItem(position) as Status
when (view.id) {
R.id.img -> {
content = "img:" + status.userAvatar
Toast.makeText(this@AnimationUseActivity, content, Toast.LENGTH_LONG).show()
}
R.id.tweetName -> {
content = "name:" + status.userName
Toast.makeText(this@AnimationUseActivity, content, Toast.LENGTH_LONG).show()
}
R.id.tweetText -> {
content = "tweetText:" + status.userName
Toast.makeText(this@AnimationUseActivity, content, Toast.LENGTH_LONG).show()
}
}// you have set clickspan .so there should not solve any click event ,just empty
} Set item long click adapter.onItemLongClickListener = BaseQuickAdapter.OnItemLongClickListener { adapter, view, position ->
Log.d(TAG, "onItemLongClick: ")
Toast.makeText(this@ItemClickActivity, "onItemLongClick" + position, Toast.LENGTH_SHORT).show()
true
} Set item child long clickFirst you need to add the childview id that you want to click on
then adapter.onItemChildLongClickListener = BaseQuickAdapter.OnItemChildLongClickListener { adapter, view, position ->
Log.d(TAG, "onItemChildLongClick: ")
Toast.makeText(this@ItemClickActivity, "onItemChildLongClick" + position, Toast.LENGTH_SHORT).show()
true
} How do I use it to add animations?// line of code to get (default for the fade effect)
mAnimationAdapter.openLoadAnimation() Do not like the fade animation can be replaced // default to 5 ways (fade, zoom, bottom to top, left to right, right to left)
mAnimationAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN); Or no you like, you can customize it // custom animation so easy
mAnimationAdapter.openLoadAnimation(BaseAnimation
{ view -> arrayOf(ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 1.1f, 1.0f), ObjectAnimator.ofFloat(view, "scaleX", 1.0f, 1.1f, 1.0f))
}) Use it to add the head to add the tail// add
mQuickAdapter.addHeaderView(getView());
mQuickAdapter.addFooterView(getView());
// remove
removeHeaderView(getView);
removeFooterView(getView);
// or
removeAllHeaderView();
removeAllFooterView(); Use it to load moremQuickAdapter.openLoadMore(PAGE_SIZE, true);
mQuickAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
@Override
public void onLoadMoreRequested() {
mRecyclerView.post(new Runnable() {
@Override
public void run() {
if (mCurrentCounter >= TOTAL_COUNTER) {
mQuickAdapter.notifyDataChangedAfterLoadMore(false);
} else {
mQuickAdapter.notifyDataChangedAfterLoadMore(DataServer.getSampleData(PAGE_SIZE), true);
mCurrentCounter = mQuickAdapter.getItemCount();
}
}
});
}
}); Set the custom to load more layoutsmQuickAdapter.setLoadingView(customView); Use groupingclass SectionAdapter constructor(layoutResId: Int, sectionHeadResId: Int, data: List<MySection>) : BaseSectionQuickAdapter<MySection, BaseViewHolder>(layoutResId, sectionHeadResId, data) {
override fun convertHead(helper: BaseViewHolder, item: MySection) {
helper.setText(R.id.header, item.header)
helper.setVisible(R.id.more, item.isMore)
helper.addOnClickListener(R.id.more)
}
override fun convert(helper: BaseViewHolder, item: MySection) {
val video = item.t as Video
when (helper.layoutPosition % 2) {
0 -> helper.setImageResource(R.id.iv, R.mipmap.m_img1)
1 -> helper.setImageResource(R.id.iv, R.mipmap.m_img2)
}
helper.setText(R.id.tv, video.name)
}
} How do I add multiple types of items?class MultipleItemQuickAdapter(context: Context, data: List<MultipleItem>) : BaseMultiItemQuickAdapter<MultipleItem, BaseViewHolder>(data) {
init {
addItemType(MultipleItem.TEXT, R.layout.item_text_view)
addItemType(MultipleItem.IMG, R.layout.item_image_view)
addItemType(MultipleItem.IMG_TEXT, R.layout.item_img_text_view)
}
override fun convert(helper: BaseViewHolder, item: MultipleItem) {
when (helper.itemViewType) {
MultipleItem.TEXT -> helper.setText(R.id.tv, item.content)
MultipleItem.IMG_TEXT -> when (helper.layoutPosition % 2) {
0 -> helper.setImageResource(R.id.iv, R.mipmap.animation_img1)
1 -> helper.setImageResource(R.id.iv, R.mipmap.animation_img2)
}
}
}
} Use setEmptyViewmQuickAdapter.setEmptyView(getView()); Use drag and drop to delete val listener = object : OnItemDragListener {
override fun onItemDragStart(viewHolder: RecyclerView.ViewHolder, pos: Int) {
Log.d(TAG, "drag start")
val holder = viewHolder as BaseViewHolder
// holder.setTextColor(R.id.tv, Color.WHITE);
}
override fun onItemDragMoving(source: RecyclerView.ViewHolder, from: Int, target: RecyclerView.ViewHolder, to: Int) {
Log.d(TAG, "move from: " + source.adapterPosition + " to: " + target.adapterPosition)
}
override fun onItemDragEnd(viewHolder: RecyclerView.ViewHolder, pos: Int) {
Log.d(TAG, "drag end")
val holder = viewHolder as BaseViewHolder
// holder.setTextColor(R.id.tv, Color.BLACK);
}
}
val onItemSwipeListener = object : OnItemSwipeListener {
override fun onItemSwipeStart(viewHolder: RecyclerView.ViewHolder, pos: Int) {
Log.d(TAG, "view swiped start: " + pos)
val holder = viewHolder as BaseViewHolder
// holder.setTextColor(R.id.tv, Color.WHITE);
}
override fun clearView(viewHolder: RecyclerView.ViewHolder, pos: Int) {
Log.d(TAG, "View reset: " + pos)
val holder = viewHolder as BaseViewHolder
// holder.setTextColor(R.id.tv, Color.BLACK);
}
override fun onItemSwiped(viewHolder: RecyclerView.ViewHolder, pos: Int) {
Log.d(TAG, "View Swiped: " + pos)
}
override fun onItemSwipeMoving(canvas: Canvas, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, isCurrentlyActive: Boolean) {
canvas.drawColor(ContextCompat.getColor(this@ItemDragAndSwipeUseActivity, R.color.color_light_blue))
// canvas.drawText("Just some text", 0, 40, paint);
}
}
class ItemDragAdapter(data: List<String>) : BaseItemDraggableAdapter<String, BaseViewHolder>(R.layout.item_draggable_view, data) {
override fun convert(helper: BaseViewHolder, item: String) {
when (helper.layoutPosition % 3) {
0 -> helper.setImageResource(R.id.iv_head, R.mipmap.head_img0)
1 -> helper.setImageResource(R.id.iv_head, R.mipmap.head_img1)
2 -> helper.setImageResource(R.id.iv_head, R.mipmap.head_img2)
}
helper.setText(R.id.tv, item)
}
}
mAdapter = ItemDragAdapter(mData)
mItemDragAndSwipeCallback = ItemDragAndSwipeCallback(mAdapter)
mItemTouchHelper = ItemTouchHelper(mItemDragAndSwipeCallback)
mItemTouchHelper.attachToRecyclerView(mRecyclerView)
//mItemDragAndSwipeCallback.setDragMoveFlags(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.UP | ItemTouchHelper.DOWN);
mItemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START or ItemTouchHelper.END)
mAdapter.enableSwipeItem()
mAdapter.setOnItemSwipeListener(onItemSwipeListener)
mAdapter.enableDragItem(mItemTouchHelper)
mAdapter.setOnItemDragListener(listener)
// mRecyclerView.addItemDecoration(new GridItemDecoration(this ,R.drawable.list_divider));
mRecyclerView.adapter = mAdapter Expandable Item// if you do not want to use inheritance, you can just implement the IExpandable interface
// AbstractExpandableItem is just a help class
data class Level0Item(var title: String, var subTitle: String) : AbstractExpandableItem<Level1Item>(), MultiItemEntity {
override fun getItemType(): Int {
return ExpandableItemAdapter.TYPE_LEVEL_0
}
override fun getLevel(): Int {
return 0
}
} in adapter code (data: List<MultiItemEntity>) : BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder>(data) {
init {
addItemType(TYPE_LEVEL_0, R.layout.item_expandable_lv0)
addItemType(TYPE_LEVEL_1, R.layout.item_expandable_lv1)
addItemType(TYPE_PERSON, R.layout.item_expandable_lv2)
}
override fun convert(holder: BaseViewHolder, item: MultiItemEntity) {
when (holder.itemViewType) {
TYPE_LEVEL_0 -> {
when (holder.layoutPosition % 3) {
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论