I have build an android app , this app is news app , I fetched data in json view , now I want to add a ads in every 3 items below , now after trying some days successfully shows ads. my listview 5 number of data , ads showing number of data show in 4 , now i want to show all number of data and every three items below ads
public View getView(int i, View view, ViewGroup viewGroup) {
if ((i + 1) / 3 == 1){
View ad_view=LayoutInflater.from(c).inflate(R.layout.ad_layout,viewGroup,false);
AdView mAdView = ad_view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
return ad_view;
} else {
if (view == null) {
view = LayoutInflater.from(c).inflate(R.layout.model_result, viewGroup, false);
}
TextView match_h = (TextView) view.findViewById(R.id.heding);
User user = (User) this.getItem(i);
final String mach_hed = user.getMathch_hed();
match_h.setText(mach_hed);
return view;
}
}
Instead of (i + 1) / 3 == 1)
try (i + 1) % 4 == 0)
If will show ads, every 4th time. That means, after every 3 item, one ad will be shown.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.