Crash github.com/siralam/LoopingViewPager Android studio

问题描述 投票:0回答:1

我正在学习有关基本应用程序的教程。该代码已被弃用,因此我在单个图像上进行了处理。但是现在,我每次活动时都崩溃。我知道它在这里,因为在开始这一部分的应用之前,它运行良好。

public class MyBestDealsAdapter extends LoopingPagerAdapter<BestDealModel> {

    @BindView(R.id.img_best_deal)
    ImageView img_best_deal;
    @BindView(R.id.txt_best_deals)
    TextView txt_best_deals;

    Unbinder unbinder;

    public MyBestDealsAdapter(Context context, List<BestDealModel> itemList, boolean isInfinite) {
        super(context, itemList, isInfinite);
       // this.context = context;
        //this.BestDealModel= itemList;   **this is what I tried**
    }

    @Override
    protected View inflateView(int viewType, ViewGroup container, int listPosition) {
        return LayoutInflater. **this context for some reason is getting flagged y tried creating Context context and the flagg goes away but still crash** from(context).inflate(R.layout.layout_best_deals_items,container,false);
    }

    @Override
    protected void bindView(View convertView, int listPosition, int viewType) {
        unbinder = ButterKnife.bind(this,convertView);
        //set data
        Glide.with(convertView).load **same here for itemList i tried BestDealModel itemlist flag gone still** crash(itemList.get(listPosition).getImage()).into(img_best_deal);
android crash deprecated
1个回答
0
投票
public class MyBestDealsAdapter extends LoopingPagerAdapter<BestDealModel> {
private final List<BestDealModel> itemList;
private final boolean isInfinite;
private Context context;

@BindView(R.id.img_best_deal)
ImageView img_best_deal;
@BindView(R.id.txt_best_deal)
TextView txt_best_deal;

Unbinder unbinder;


   public MyBestDealsAdapter(Context context,List<BestDealModel> itemList, boolean isInfinite) {
    super(context, itemList, isInfinite);
       this.context = context;
       this.itemList = itemList;
       this.isInfinite = isInfinite;
   }

@Override
protected void bindView(View convertView, int listPosition, int viewType) {
    unbinder = ButterKnife.bind(this,convertView);

    //set data
    Glide.with(convertView).load(itemList.get(listPosition).getimage()).into(img_best_deal);
    txt_best_deal.setText(itemList.get(listPosition).getName());
}

@Override
protected View inflateView(int viewType, ViewGroup container, int listPosition) {
    return LayoutInflater.from(context).inflate(R.layout.layout_best_deal_item, container, false);
}

}

这是解决的方法

© www.soinside.com 2019 - 2024. All rights reserved.