gpt4 book ai didi

android - 在此适配器中添加一个 AdView

转载 作者:行者123 更新时间:2023-11-29 02:26:20 25 4
gpt4 key购买 nike

我想在这个适配器的第二个位置添加一个广告 View 。我必须为此改变什么?在过去的两个小时里,我尝试了很多。我可以在加载列表后插入吗?

这是我的适配器代码:

public class FeedsAdapter extends RecyclerView.Adapter<FeedsAdapter.MyViewHolder> {
ArrayList<FeedItem> feedItems;
MainActivity context;
private static final String FILENAME = "prefsSettings";
private static final String VAL_KEY7 = "news_format";

public FeedsAdapter(MainActivity context, ArrayList<FeedItem> feedItems) {
this.feedItems = feedItems;
this.context = context;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME, 0);
String theme = sharedPrefs.getString(VAL_KEY7, "little");
View view = null;
if(theme.equals("big")) {
view = LayoutInflater.from(context).inflate(R.layout.custum_row_news_item, parent, false);
} else if (theme.equals("little")) {
view = LayoutInflater.from(context).inflate(R.layout.custum_row_news_item_smal, parent, false);
} else if (theme.equals("none")) {
view = LayoutInflater.from(context).inflate(R.layout.custum_row_news_item_none, parent, false);
}
MyViewHolder holder = new MyViewHolder(view);
return holder;
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME, 0);
String theme = sharedPrefs.getString(VAL_KEY7, "little");
YoYo.with(Techniques.FadeIn).playOn(holder.cardView);
final FeedItem current = feedItems.get(position);
holder.Title.setText(current.getTitle());
holder.Description.setText(current.getDescription());
if(theme.equals("big")) {
holder.Date.setText(current.getPubDate());
Picasso.with(context).load(current.getThumbnailUrl()).resize(150, 100).into(holder.Thumbnail);
} else if (theme.equals("little")) {
Picasso.with(context).load(current.getThumbnailUrl()).resize(150, 100).into(holder.Thumbnail);
}
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, NewsDetails.class);
intent.putExtra("Link", current.getLink());
context.startActivity(intent);
}
});
}

@Override
public int getItemCount() {
int size = 0;
if(feedItems != null){
size = feedItems.size();
}
return size;
}

public class MyViewHolder extends RecyclerView.ViewHolder {
TextView Title, Description, Date;
ImageView Thumbnail;
CardView cardView;

public MyViewHolder(View itemView) {
super(itemView);
Title = (TextView) itemView.findViewById(R.id.title_text);
Description = (TextView) itemView.findViewById(R.id.description_text);
Date = (TextView) itemView.findViewById(R.id.date_text);
Thumbnail = (ImageView) itemView.findViewById(R.id.thumb_img);
cardView = (CardView) itemView.findViewById(R.id.cardview);
}
}
}

最佳答案

当您在数组列表中添加项目时,在第二个位置添加空数据,并在适配器类中在第二个位置添加 View 。

关于android - 在此适配器中添加一个 AdView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51986980/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com