@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final MoPubSampleAdUnit adConfiguration = MoPubSampleAdUnit.fromBundle(getArguments()); final View view = inflater.inflate(R.layout.banner_detail_fragment, container, false); final DetailFragmentViewHolder views = DetailFragmentViewHolder.fromView(view); mMoPubView = (MoPubView) view.findViewById(R.id.banner_mopubview); hideSoftKeyboard(views.mKeywordsField); final String adUnitId = adConfiguration.getAdUnitId(); views.mDescriptionView.setText(adConfiguration.getDescription()); views.mAdUnitIdView.setText(adUnitId); views.mLoadButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { final String keywords = views.mKeywordsField.getText().toString(); loadMoPubView(adUnitId, keywords); } }); mMoPubView.setBannerAdListener(this); loadMoPubView(adUnitId, null); return view; }
private void loadMoPubView(MoPubView moPubView, String adUnitId, String keywords) { if (moPubView == null) { logToast(getActivity(), "Unable to inflate MoPubView from xml."); return; } try { validateAdUnitId(adUnitId); } catch (IllegalArgumentException exception) { logToast(getActivity(), exception.getMessage()); return; } moPubView.setBannerAdListener(this); moPubView.setAdUnitId(adUnitId); moPubView.setKeywords(keywords); moPubView.loadAd(); }