Giter VIP home page Giter VIP logo

Comments (2)

zguop avatar zguop commented on May 29, 2024

用BaseQuickAdapter, setOnItemClickListener(BaseQuickAdapter adapter, View view, int position) 参数position 是 通过 int position = baseViewHolder.getAdapterPosition(); 回调出来的实际轮播数量的position,这个角标没有经过转换= =,因此这里通过banner.getCurrentPager()获取当前显示的position。

现在针对你你的这种情况分析是,点击了两侧的item,
回调出来的参数position还是通过int position = baseViewHolder.getAdapterPosition()没有经过转换,角标不正确;banner.getCurrentPager()是当前页的,角标不正确;

解决方案,参考下哈:

public class ImageAdapter extends BaseQuickAdapter<Object, BaseViewHolder> {
public ImageAdapter() {
    super(R.layout.item_image);
}
  //看这里 回调出正确的position
@Override
public void onBindViewHolder(@NonNull final BaseViewHolder holder, final int position) {
    super.onBindViewHolder(holder, position);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setOnItemClick(holder.itemView, position);
        }
    });
}

@Override
protected void convert(@NonNull BaseViewHolder helper, Object item) {
    Glide.with(mContext)
            .load(item)
            .into((ImageView) helper.getView(R.id.img));
}

}

from banner.

PascalTang avatar PascalTang commented on May 29, 2024

非常感謝

from banner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.