MoPubAdAdapter /2.4.0
public class MoPubAdAdapter
Contains methods to request native ads for a stream (a ListView
). For a manual native ad integration, refer to MoPubNative.java
.
Public Methods
public void /clearAds() /+2.4.0
-
Description: Stops loading ads, immediately clearing any ads currently in the stream.
-
Parameters: None.
public void /destroy() /+2.4.0
-
Description: Removes existing ad instance in session. Used when finished showing an ad to free up existing resources.
-
Parameters: None.
public int /getAdjustedPosition(int originalPosition) /+2.4.0
-
Description: Returns the adjusted position of an item in the stream, after the insertion of ads in the stream.
-
Parameters:
originalPosition
: An integer indicating the original cell index.
public int /getCount() /+2.4.0
-
Description: Returns the number of items in the stream, including ads.
-
Parameters: None.
public Object /getItem(int position) /+2.4.0
-
Description: For ad items, returns an ad data object. For non ad items, calls the original adapter using the original item position.
-
Parameters:
position
: An integer representing the position to check.
public long /getItemId(int position) /+2.4.0
-
Description: For ads, this ID will be a negative integer. If it’s possible that this ID may collide with the original adapter’s IDs,
false
should be returned fromhasStableIds()
. -
Parameters:
position
: An integer representing the position to check.
public int /getItemViewType(int position) /+2.4.0
-
Description: For ad items, returns a number greater than or equal to the view type count for the underlying adapter. For non-ad items, calls the original adapter using the original ad position.
-
Parameters:
position
: An integer representing the position to check.
public int /getOriginalPosition(int position) /+2.4.0
-
Description: Returns the original position of an item in the stream, prior to the insertion of ads in the stream.
-
Parameters:
position
: An integer representing the position to check.
public View /getView(int position, View view, ViewGroup viewGroup) /+2.4.0
-
Description: For ad items, returns an ad view for the underlying position. For non-ad items, calls the original adapter using the original ad position.
-
Parameters:
position
: An integer representing the position to check.view
: AView
into which to render data. Can be null.viewGroup
: TheViewGroup
instance to check.
public int /getViewTypeCount() /+2.4.0
-
Description: Returns the view type count of the original adapter, plus the number of possible view types for ads.
-
Parameters: None.
public boolean /hasStableIds() /+2.4.0
-
Description: Returns the value returned by
hasStableIds()
on the original adapter. -
Parameters: None.
public void /insertItem(int originalPosition) /+2.4.0
-
Description: Inserts a content row at the given position, adjusting ad positions accordingly.
-
Parameters:
originalPosition
: An integer representing the position to check.
public boolean /isAd(int position) /+2.4.0
-
Description: Returns
true
if the given position is ad;false
otherwise. -
Parameters:
position
: An integer representing the position to check.
public boolean /isEmpty() /+2.4.0
-
Description: Returns
true
the adapter empty, calling through to the original adapter;false
otherwise. -
Parameters: None.
public boolean /isEnabled(int position) /+2.4.0
-
Description: Returns
true
if the item at the specified position is not a separator;false
otherwise. (A separator is a non-selectable, non-clickable item). The result is unspecified if position is invalid. -
Parameters:
position
: An integer representing the position to check.
public void /loadAds(String adUnitId) /+2.4.0
-
Description: Starts loading ads from the MoPub server.
-
Parameters:
adUnitId
: MoPub ad unit ID String.
public void /loadAds(String adUnitId, RequestParameters requestParameters) /+2.4.0
-
Description: Starts loading ads from the MoPub server, using the given request targeting information.
-
Parameters:
adUnitId
: MoPub ad unit ID String.requestParameters
: An object for specifying targeting data such as keywords, location (deprecated as of 5.12.0), and customer ID. Refer toRequestParameters.java
.
public void /refreshAds(ListView listView, String adUnitId) /+2.4.0
-
Description: Manually sends out a new ad request, while preserving the scroll position. Used to issue a new ad request and start a new refresh cycle.
-
Parameters:
listView
: TheListView
instance.adUnitId
: MoPub ad unit ID String.
public void /refreshAds(ListView listView, String adUnitId, RequestParameters requestParameters) /+2.4.0
-
Description: Manually sends out a new ad request with additional targeting data in the given
ListView
while preserving the scroll position. Used to issue a new ad request with additional targeting information and start a new refresh cycle. -
Parameters:
listView
: TheListView
instance.adUnitId
: MoPub ad unit ID String.requestParameters
: An object for specifying targeting data such as keywords, location (deprecated as of 5.12.0), and customer ID. Refer toRequestParameters.java
.
public void /registerAdRenderer(MoPubAdRenderer adRenderer) /+2.4.0
-
Description: Registers a
MoPubStaticNativeAdRenderer
, supporting a specific native ad format, to use when displaying ads in the stream. Note that if multiple ad renderers support a specific native ad format, the first one registered will be used. -
Parameters:
adRenderer
: The renderer instance (MoPub’s or network’s) to be registered.
public void /removeItem(int originalPosition) /+2.4.0
-
Description: Removes the content row at the given position, adjusting ad positions accordingly.
-
Parameters:
originalPosition
: The original content position at which to remove an item. For an adjusted position,getOriginalPosition()
should be called to get this value.
public void /setAdLoadedListener(MoPubNativeAdLoadedListener listener) /+2.4.0
-
Description: Sets a listener that will be called after the SDK loads new ads from the server and places them into the stream.
-
Parameters:
listener
: The current instance ofMoPubNativeAdLoadedListener
.
public void /setOnClickListener(ListView listView, AdapterView.OnItemClickListener listener) /+2.4.0
-
Description: Sets an on click listener for the given
ListView
, automatically adjusting the listener callback positions based on ads in the adapter. -
Parameters:
listView
: TheListView
for this adapter.listener
: An on click listener.
public void /setOnItemLongClickListener(ListView listView, AdapterView.OnItemLongClickListener listener) /+2.4.0
-
Description: Sets an on long click listener for the given
ListView
, automatically adjusting the listener callback positions based on ads in the adapter. -
Parameters:
listView
: TheListView
for this adapter.listener
: An on click listener.
public void /setOnItemSelectedListener(ListView listView, AdapterView.OnItemSelectedListener listener) /+2.4.0
-
Description: Sets an on item selected listener for the given
ListView
, automatically adjusting the listener callback positions based on ads in the adapter. -
Parameters:
listView
: TheListView
for this adapter.listener
: An on click listener.
public void /setSelection(ListView listView, int originalPosition) /+2.4.0
-
Description: Sets the currently selected item in the
ListView
, automatically adjusting the position based on ads in the adapter. -
Parameters:
originalPosition
: The original content position before loading ads. For an adjusted position,getOriginalPosition()
should be called to get this value.
public void /smoothScrollToPosition(ListView listView, int originalPosition) /+2.4.0
-
Description: Scrolls an item in the
ListView
, automatically adjusting the position based on ads in the adapter. -
Parameters:
originalPosition
: The original content position before loading ads. For an adjusted position,getOriginalPosition()
should be called to get this value.
Last updated December 03, 2020
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2020 MoPub (a division of Twitter, Inc.)