I have listview with cursoradapter. Now i want to implement native express ads in listview.
I have seen the implementation of Native ads with simple baseAdapter,in that generally we are using List<Object>
for passing data to adapter and check type of item inside getView()
method to add ads.
@Override
public View getView(int position, View convertView, ViewGroup parent)
throws IllegalArgumentException {
Object item = getItem(position);
if (item instanceof Listing) {
// Listing items already have all the data required, so they just need to be displayed.
return listingLayout;
} else if (item instanceof AdPlacement) {
return ((AdPlacement) item).getView(convertView, parent);
} else {
// Any unknown items will cause exceptions, though this shouldn't ever happen.
throw new IllegalArgumentException(
String.format("Adapter can't handle getView() for list item of type %s",
item.getClass().getName()));
}
}
How to check this condition in cursoradapter as cursoradapter only have method newItem() with cursor details
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = LayoutInflater.from(context).inflate(R.layout.list_item_station, parent, false);
ViewHolder holder = new ViewHolder();
v.setTag(holder);
return v;
}
How to add native ads after every 10 items in cursoradapter
Bellow is the current code i am using to add data in the list.
public class StationsCursorAdapter extends CursorAdapter{
public StationsCursorAdapter(Context context) {
super(context, null, true);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = LayoutInflater.from(context).inflate(R.layout.list_item_station, parent, false);
ViewHolder holder = new ViewHolder();
v.setTag(holder);
return v;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
holder.titleTextView.setText(cursor.getString(cursor.getColumnIndex(Station.NAME)));
}
private static final class ViewHolder {
TextView titleTextView;
}
}