android view 随机位置,android-如何在RecyclerView之间随机放置广告?

我在应用程序中使用了FastAdapter,我想在RecyclerView之间随机放置广告.例如,例如,在3个RecyclerView项目之后,然后在4个项目之后,然后在2个项目之后的广告,依此类推.

这就是我使用FastAdapter的方式:

FastItemAdapter fastItemAdapter = new FastItemAdapter<>();

fastItemAdapter.withSelectable(true);

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

recyclerView.setHasFixedSize(true);

recyclerView.setLayoutManager(linearLayoutManager);

recyclerView.setItemAnimator(new DefaultItemAnimator());

HRequest hRequest = new HRequest(imageUID);

fastItemAdapter.add(helpRequest);

recyclerView.setAdapter(fastItemAdapter);

这是HRequest.java文件的代码:

public class HRequest extends AbstractItem {

public String imageURL;

public HRequest() {

}

public HRequest(String imageURL) {

this.imageURL = imageURL;

}

// Fast Adapter methods

@Override

public int getType() {

return R.id.recycler_view;

}

@Override

public int getLayoutRes() {

return R.layout.h_request_list_row;

}

@Override

public void bindView(ViewHolder holder) {

super.bindView(holder);

holder.imageURL.setText(imageURL);

}

// Manually create the ViewHolder class

protected static class ViewHolder extends RecyclerView.ViewHolder {

TextView imageURL;

public ViewHolder(View itemView) {

super(itemView);

imageURL = (TextView)itemView.findViewById(R.id.imageURL);

if (!imageURL.getText().toString().isEmpty()) {

if (imageURL.getText().toString().startsWith("https://firebasestorage.googleapis.com/") || imageURL.getText().toString().startsWith("content://")) {

Picasso.with(itemView.getContext())

.load(imageURL.getText().toString())

.into(homelessImage);

} else {

Toast.makeText(itemView.getContext(), "some problem", Toast.LENGTH_SHORT).show();

}

} else {

Toast.makeText(itemView.getContext(), "no imageUID found", Toast.LENGTH_SHORT).show();

}

}

}

}

我怎样才能实现自己想要的?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值