I have integarted with Mopub for displaying ads in my android application. I am able to display bannner and interstitial ads but not native ads,
layout file code,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/note_title_label"
style="?android:listSeparatorTextViewStyle"
/>
<EditText android:id="@+id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/note_title_hint"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/note_details_label"
style="?android:listSeparatorTextViewStyle"
/>
<EditText android:id="@+id/note_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/note_details_hint"
/>
<Button android:id="@+id/note_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
<CheckBox android:id="@+id/note_solved"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="@string/note_solved_label"
/>
<RelativeLayout android:id="@+id/native_ad_layout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="50dp">
>
<ImageView android:id="@+id/native_ad_main_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView android:id="@+id/native_ad_icon_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/native_ad_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/native_ad_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
</LinearLayout>
Logic in fragment.java(associated with above layout) file for displaying native ads,
@TargetApi(11)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_note, parent, false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (NavUtils.getParentActivityName(getActivity()) != null) {
getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
mTitleField = (EditText)v.findViewById(R.id.note_title);
mTitleField.setText(mNote.getTitle());
mTitleField.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence c, int start, int before, int count)
{
String title=Character.toUpperCase(c.toString().charAt(0)) + c.toString().substring(1);
mNote.setTitle(title);
}
public void beforeTextChanged(
CharSequence c, int start, int count, int after)
{// This space intentionally left blank
}
public void afterTextChanged(Editable c) {
// This one too
}
});
mDetailsField = (EditText)v.findViewById(R.id.note_details);
mDetailsField.setText(mNote.getDetails());
mDetailsField.addTextChangedListener(new TextWatcher() {
public void onTextChanged(
CharSequence c, int start, int before, int count)
{
mNote.setDetails(c.toString());
}
public void beforeTextChanged(
CharSequence c, int start, int count, int after)
{// This space intentionally left blank
}
public void afterTextChanged(Editable c) {
// This one too
}
});
mDateButton = (Button)v.findViewById(R.id.note_date);
mDateButton.setText(mNote.getDate().toString());
//mDateButton.setEnabled(false);
mDateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
FragmentManager fm = getActivity()
.getSupportFragmentManager();
//DatePickerFragment dialog = new DatePickerFragment();
DatePickerFragment dialog = DatePickerFragment
.newInstance(mNote.getDate());
dialog.setTargetFragment(NoteFragment.this, REQUEST_DATE);
dialog.show(fm, DIALOG_DATE);
}
});
mSolvedCheckBox = (CheckBox)v.findViewById(R.id.note_solved);
mSolvedCheckBox.setChecked(mNote.isSolved());
mSolvedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// set the note's solved property
mNote.setSolved(isChecked);
}
});
/* Button reportButton = (Button)v.findViewById(R.id.note_reportButton);
reportButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("vnd.android-dir/mms-sms");
i.putExtra(Intent.EXTRA_TEXT, getNoteReport());
i.putExtra(Intent.EXTRA_SUBJECT,
mNote.getTitle());
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setData(Uri.parse("sms:"));
sendIntent.putExtra("sms_body", "test man text");
startActivity(sendIntent);
}
});*/
//advertising start
MoPubNative.MoPubNativeListener moPubNativeListener = new MoPubNative.MoPubNativeListener() {
@Override
public void onNativeLoad(NativeResponse nativeResponse) {
// ...
}
@Override
public void onNativeFail(NativeErrorCode errorCode) {
// ...
}
@Override
public void onNativeImpression(View view) {
// ...
}
@Override
public void onNativeClick(View view) {
// ...
};
};
MoPubNative moPubNative = new MoPubNative(this.getActivity().getApplicationContext(), "248504aaf06d4a759a59d0615a5bdb54", moPubNativeListener);
Location exampleLocation = new Location("com.genedevelopers.android.yournote");
exampleLocation.setLatitude(23.1);
exampleLocation.setLongitude(42.1);
exampleLocation.setAccuracy(100);
RequestParameters requestParameters = new RequestParameters.Builder()
.keywords("gender:m,age:27")
.location(exampleLocation)
.build();
moPubNative.makeRequest(requestParameters);
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.list_item_note)
.mainImageId(R.id.native_ad_main_image)
.iconImageId(R.id.native_ad_icon_image)
.titleId(R.id.native_ad_title)
.textId(R.id.native_ad_text)
.build();
//advertising end
return v;
}
so please someone tell me what is wrong in the code, or if anybody having the sample code on how to integrate mopub native ads to android application please share it....