I've been working inRecyclerView and Google Volley for parsing JSON Then I added google native ads!
I following tutorial on this link
So I did change the RecyclerViewAdapter like google developers guideline!
It says that the List has to be a List of Object (List<Object>) So I changed this and a few other things in the Adapter!
Then Android Studio shows no Errors and I'm able to launch the Application. But when I'm going to open the Fragment with the mentioned RecyclerView it crashes.
It says:
java.lang.ClassCastException: com.graciaapps.nameoncards.instance.greetoptions.SubOptionOneInstance cannot be cast to com.google.android.gms.ads.NativeExpressAdView
onBindViewHolder
NativeExpressAdView adView = (NativeExpressAdView)greetingInstanceList.get(position);
Thanks in advance!
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to google-adm...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
Hello Deepika,First of all, Thank You allot for quick help. :). Actually I knew, Purely it is a implementation issue. All I was is looking for some help regarding this. Because after lot of effort (Almost 15 days), I am not getting anywhere.Thank You Again.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Deepika,
Thank You alott. Sure, How can i send you my app code personally? Can you share email mam?
Thank you again 😊
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Deepika,
Thank You alott. Sure, How can i send you my app code personally? Can you share email mam?
Thank you again 😊
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hii Deepika,Thank You for support. Ohhkkkk, Now I understand where is the problem. Let me make changes into my project. I will surely let you know about it mam.Thank You again.Jitander VermaAndroid Developer and founderSctar Labs.
public class MyAdapterSecondPage extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Context c;
Vibrator vib;
String root = Environment.getExternalStorageDirectory().toString();
public static int myClickedImageId;
ConnectivityManager cm;
NetworkInfo activeNetwork;
boolean isConnected;
String packageName = "";
public String urlLink;
public int imageId;
private final ArrayList<Object> mRecyclerViewItems;
private static final int MENU_ITEM_VIEW_TYPE = 0;
private static final int NATIVE_EXPRESS_AD_VIEW_TYPE = 1;
private final int VIEW_TYPE_LOADING = 2;
private boolean isLoading;
private int visibleThreshold = 5;
private int lastVisibleItem, totalItemCount;
private static MainActivity ma = new MainActivity();
private OnLoadMoreListener onLoadMoreListener;
public MyAdapterSecondPage(Context c, ArrayList<Object> recyclerViewItems) {
this.c = c;
this.mRecyclerViewItems = recyclerViewItems;
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) ma.rv.getLayoutManager();
ma.rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
totalItemCount = linearLayoutManager.getItemCount();
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
if (!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
if (onLoadMoreListener != null) {
onLoadMoreListener.onLoadMore();
}
isLoading = true;
}
}
});
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == MENU_ITEM_VIEW_TYPE) {
Log.d("onCreateViewHolder", "" + "MENU_ITEM_VIEW_TYPE");
View menuItemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.quote_grid_model_default, parent, false);
return new MyHolder(menuItemLayoutView);
} else if (viewType == NATIVE_EXPRESS_AD_VIEW_TYPE) {
Log.d("onCreateViewHolder", "" + "NATIVE_EXPRESS_AD_VIEW_TYPE");
View nativeExpressLayoutView = LayoutInflater.from(
parent.getContext()).inflate(R.layout.native_express_ad_container,
parent, false);
return new NativeExpressAdViewHolder(nativeExpressLayoutView);
} else {
Log.d("onCreateViewHolder", "" + "VIEW_TYPE_LOADING");
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_loading, parent, false);
return new LoadingViewHolder(view);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
int viewType = getItemViewType(position);
if (viewType == MENU_ITEM_VIEW_TYPE) {
Log.d("onBindViewHolder", "" + "MENU_ITEM_VIEW_TYPE");
MyHolder menuItemHolder = (MyHolder) holder;
PicassoClient.downloadImage(c, ((TVShow) mRecyclerViewItems.get(position)).getUrl().toString().trim(), menuItemHolder.img);
menuItemHolder.nameTxt.setText(((TVShow) mRecyclerViewItems.get(position)).getName().toString().trim());
} else if (viewType == NATIVE_EXPRESS_AD_VIEW_TYPE) {
Log.d("onBindViewHolder", "" + "NATIVE_EXPRESS_AD_VIEW_TYPE");
NativeExpressAdViewHolder nativeExpressHolder =
(NativeExpressAdViewHolder) holder;
NativeExpressAdView adView =
(NativeExpressAdView) (mRecyclerViewItems.get(position));
ViewGroup adCardView = (ViewGroup) nativeExpressHolder.itemView;
if (adCardView.getChildCount() > 0) {
adCardView.removeAllViews();
}
if (adView.getParent() != null) {
((ViewGroup) adView.getParent()).removeView(adView);
}
adCardView.addView(adView);
} else if (viewType == VIEW_TYPE_LOADING) {
Log.d("onBindViewHolder", "" + "VIEW_TYPE_LOADING");
LoadingViewHolder loadingViewHolder = (LoadingViewHolder) holder;
loadingViewHolder.progressBar.setIndeterminate(true);
}
}
public class MyHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView img;
TextView nameTxt;
public MyAdapterFirstPage myAdapterFirstPage = new MyAdapterFirstPage(null, null);
public MyHolder(View itemView) {
super(itemView);
nameTxt = (TextView) itemView.findViewById(R.id.nameTxt);
img = (ImageView) itemView.findViewById(R.id.movieImage);
urlLink = myAdapterFirstPage.setUrlLink;
imageId = 1;
packageName = "/FacebookImageSharingDir/ActressPhotos";
File FacebookImageSharingDirectoryObject = new File(root + packageName);
if (!FacebookImageSharingDirectoryObject.exists()) {
FacebookImageSharingDirectoryObject.mkdirs();
}
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
isConnected = isConnected();
Log.d("myClickedImageId", "" + myClickedImageId);
if (isConnected) {
myClickedImageId = getAdapterPosition() + imageId;
// Intent i = new Intent(c, MainActivityImageView.class);
// c.startActivity(i);
} else {
Toast.makeText(getApplicationContext(), "" + "Sorry! Not Connected To Internet.", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public void onClick(View view) {
MyAdapterFirstPage myAdapterFirstPage = new MyAdapterFirstPage(null, null);
try {
vib = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
vib.vibrate(13);
} catch (Exception e) {
e.printStackTrace();
}
urlLink = myAdapterFirstPage.setUrlLink;
imageId = 1;
}
}
public class NativeExpressAdViewHolder extends RecyclerView.ViewHolder {
NativeExpressAdViewHolder(View view) {
super(view);
}
}
@Override
public int getItemCount() {
if (mRecyclerViewItems == null) {
return 0;
} else {
return mRecyclerViewItems.size();
}
}
@Override
public int getItemViewType(int position) {
if (mRecyclerViewItems.get(position) == null) {
return VIEW_TYPE_LOADING;
} else {
if (position % MainActivity.ITEMS_PER_AD != 0) {
return MENU_ITEM_VIEW_TYPE;
} else {
return NATIVE_EXPRESS_AD_VIEW_TYPE;
}
}
}
public boolean isConnected() {
cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null
&& activeNetwork.isConnectedOrConnecting();
}
private class LoadingViewHolder extends RecyclerView.ViewHolder {
public ProgressBar progressBar;
public LoadingViewHolder(View view) {
super(view);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar1);
}
}
public void setOnLoadMoreListener(OnLoadMoreListener mOnLoadMoreListener) {
this.onLoadMoreListener = mOnLoadMoreListener;
}
public void setLoaded() {
isLoading = false;
}
}
public class MainActivity extends AppCompatActivity {
public static RecyclerView rv;
MyAdapterSecondPage adapter;
private static final int REQUEST_READ_WRITE_PERMISSION = 786;
public static ShareDialog shareDialog;
public CallbackManager callbackManager;
public LoginManager manager;
public List<String> permissionNeeds;
public static final int ITEMS_PER_AD = 8;
private static final int NATIVE_EXPRESS_AD_HEIGHT = 150;
private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1072772517";
private ArrayList<Object> mRecyclerViewItems = new ArrayList<>();
MyAdapterFirstPage myAdapterFirstPage = new MyAdapterFirstPage(null, null) ;
TVShow tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quote_grid_activity_main);
requestPermission();
rv = (RecyclerView) findViewById(R.id.rv);
rv.setLayoutManager(new LinearLayoutManager(this));
if (getApplicationContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
rv.setLayoutManager(new GridLayoutManager(getApplicationContext(), 1));
} else {
rv.setLayoutManager(new GridLayoutManager(getApplicationContext(), 1));
}
addImages();
addNativeExpressAds();
setUpAndLoadNativeExpressAds();
adapter = new MyAdapterSecondPage(getApplicationContext(), mRecyclerViewItems);
rv.setAdapter(adapter);
//set load more listener for the RecyclerView adapter
adapter.setOnLoadMoreListener(new OnLoadMoreListener() {
@Override
public void onLoadMore() {
if (mRecyclerViewItems.size() <= 20) {
Log.d("Iaminset", ""+"I am in setOnLoadMoreListener "+ mRecyclerViewItems.size());
mRecyclerViewItems.add(null);
adapter.notifyItemInserted(mRecyclerViewItems.size() - 1);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mRecyclerViewItems.remove(mRecyclerViewItems.size() - 1);
adapter.notifyItemRemoved(mRecyclerViewItems.size());
//Generating more data
int index = mRecyclerViewItems.size();
int end = index + 10;
for (int i = index; i < end; i++) {
tv = new TVShow();
tv.setUrl(myAdapterFirstPage.setUrlLink + "(" + i + ").jpg");
tv.setName("" + i);
mRecyclerViewItems.add(tv);
}
adapter.notifyDataSetChanged();
adapter.setLoaded();
}
}, 5000);
} else {
Toast.makeText(MainActivity.this, "Loading data completed", Toast.LENGTH_SHORT).show();
}
}
});
}
private void addImages() {
MyAdapterFirstPage myAdapterFirstPage = new MyAdapterFirstPage(null, null) ;
TVShow tv;
for (int i = 1; i <= 10; ++i) {
tv = new TVShow();
tv.setUrl(myAdapterFirstPage.setUrlLink + "(" + i + ").jpg");
tv.setName("" + i);
mRecyclerViewItems.add(tv);
}
}
private void addNativeExpressAds() {
for (int i = 0; i <= mRecyclerViewItems.size(); i += ITEMS_PER_AD) {
final NativeExpressAdView adView = new NativeExpressAdView(MainActivity.this);
mRecyclerViewItems.add(i, adView);
}
}
private void setUpAndLoadNativeExpressAds() {
rv.post(new Runnable() {
@Override
public void run() {
final float scale = MainActivity.this.getResources().getDisplayMetrics().density;
// Set the ad size and ad unit ID for each Native Express ad in the items list.
Log.d("MRVSIZE", ""+mRecyclerViewItems.size());
for (int i = 0; i <= mRecyclerViewItems.size(); i += ITEMS_PER_AD) {
final NativeExpressAdView adView =
(NativeExpressAdView) mRecyclerViewItems.get(i);
final CardView cardView = (CardView) findViewById(R.id.ad_card_view);
final int adWidth = cardView.getWidth() - cardView.getPaddingLeft()
- cardView.getPaddingRight();
AdSize adSize = new AdSize((int) (adWidth / scale), NATIVE_EXPRESS_AD_HEIGHT);
adView.setAdSize(adSize);
adView.setAdUnitId(AD_UNIT_ID);
}
// Load the first Native Express ad in the items list.
loadNativeExpressAd(0);
}
});
}
private void loadNativeExpressAd(final int index) {
if (index >= mRecyclerViewItems.size()) {
return;
}
Object item = mRecyclerViewItems.get(index);
if (!(item instanceof NativeExpressAdView)) {
throw new ClassCastException("Expected item at index " + index + " to be a Native"
+ " Express ad.");
}
final NativeExpressAdView adView = (NativeExpressAdView) item;
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
loadNativeExpressAd(index + ITEMS_PER_AD);
}
@Override
public void onAdFailedToLoad(int errorCode) {
Log.e("MainActivity", "The previous Native Express ad failed to load. Attempting to"
+ " load the next Native Express ad in the items list.");
loadNativeExpressAd(index + ITEMS_PER_AD);
}
});
// Load the Native Express ad.
adView.loadAd(new AdRequest.Builder().build());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
Log.e("mydata", data.toString());
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_READ_WRITE_PERMISSION && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Toast.makeText(MainActivity.this, "Welcome!!!", Toast.LENGTH_SHORT).show();
}
}
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_READ_WRITE_PERMISSION);
} else {
}
}
}
// TVShow.java
public class TVShow {
String name;
String url;
public TVShow() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
Hi Deepika,
Its Working Now. All is do is call methods inside onResponse() method which were loading ads in NativeExpressAdviews..Thank You Alot for support.
On Sat, Jun 3, 2017 at 4:28 PM, Jitander Verma <jitande...@gmail.com> wrote:
Hi Deepika,Good Evening,Can You please help me with code. How can i make wait for json to be added to array. I follow stack overflow whole week also do lot of code. but still not getting anywhere.Thanks in Advance.Jitander Verma.
On Fri, May 26, 2017 at 10:06 AM, Jitander Verma <jitande...@gmail.com> wrote:
Hii Deepika,Thank You for support. Ohhkkkk, Now I understand where is the problem. Let me make changes into my project. I will surely let you know about it mam.Thank You again.Jitander VermaAndroid Developer and founderSctar Labs.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/DTMvw_aPkPE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
package com.noticeboard.domain.noticeboard;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.google.android.gms.ads.NativeExpressAdView;
import java.util.List;
/**
* Created by MayankKutmutia on 8/9/2017.
*/
public class ActivitesTwoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<Object> mRecyclerViewItems;
private static final int AD_VIEW_TYPE=1;
private static final int MENU_ITEM_VIEW_TYPE=0;
private Context context;
private int lastPosition = -1;
public ActivitesTwoAdapter(Context context,List<Object> aca) {
this.mRecyclerViewItems = aca;
this.context = context;
}
public static class MenuViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView mTextView,mTextView1,mTextView2,mTextView3,mTextView4;
public CardView cardView;
public ImageView imageView;
public MenuViewHolder(View v) {
super(v);
mTextView = (TextView) v.findViewById(R.id.info_text);
mTextView1 = (TextView) v.findViewById(R.id.info_text1);
mTextView2 = (TextView) v.findViewById(R.id.info_text2);
mTextView3 = (TextView) v.findViewById(R.id.info_text3);
mTextView4 = (TextView) v.findViewById(R.id.info_text4);
imageView = (ImageView) v.findViewById(R.id.info_text5);
cardView = (CardView) v.findViewById(R.id.card_view);
}
}
public class NativeExpressAds extends RecyclerView.ViewHolder{
public NativeExpressAds(View view){
super(view);
}
}
@Override
public int getItemCount() {
return mRecyclerViewItems.size();
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
switch (viewType) {
case MENU_ITEM_VIEW_TYPE:
// create a new view
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.act_two_item, parent, false);
// set the view's size, margins, paddings and layout parameters
return new MenuViewHolder(v);
case AD_VIEW_TYPE:
default:
View nativeexpress = LayoutInflater.from(parent.getContext()).inflate(R.layout.act_two_native,parent,false);
return new NativeExpressAds(nativeexpress);
}
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder,final int position) {
int viewType = getItemViewType(position);
switch (viewType){
case MENU_ITEM_VIEW_TYPE:
MenuViewHolder menuViewHolder = (MenuViewHolder) holder;
final ActTwoTiles actTwoTiles = (ActTwoTiles) mRecyclerViewItems.get(position);
menuViewHolder.mTextView.setText(actTwoTiles.getTitle());
menuViewHolder.mTextView1.setText(actTwoTiles.getCompany());
menuViewHolder.mTextView2.setText(actTwoTiles.getDate());
menuViewHolder.mTextView3.setText(actTwoTiles.getAmount());
menuViewHolder.mTextView4.setText(actTwoTiles.getShortDescription());
Glide.with(context).load(actTwoTiles.getSourceLogo()).into(menuViewHolder.imageView);
menuViewHolder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse(actTwoTiles.getLink());
Intent websiteIntent = new Intent(Intent.ACTION_VIEW, uri);
v.getContext().startActivity(websiteIntent);
}
});
break;
/* Animation animation = AnimationUtils.loadAnimation(context,
(position > lastPosition) ? R.anim.up_from_bottom_act
: R.anim.down_from_top_act);
holder.itemView.startAnimation(animation);
lastPosition = position;*/
case AD_VIEW_TYPE:
default:
NativeExpressAds nativeExpressAds = (NativeExpressAds) holder;
NativeExpressAdView nativeExpressAdView = (NativeExpressAdView) mRecyclerViewItems.get(position);
ViewGroup adCardView = (ViewGroup) nativeExpressAds.itemView;
if (adCardView.getChildCount() > 0) {
adCardView.removeAllViews();
}
if (nativeExpressAdView.getParent() != null) {
((ViewGroup) nativeExpressAdView.getParent()).removeView(nativeExpressAdView);
}
// Add the Native Express ad to the native express ad view.
adCardView.addView(nativeExpressAdView);
}
}
@Override
public int getItemViewType(int position) {
return (position%6 == 0)? AD_VIEW_TYPE:MENU_ITEM_VIEW_TYPE;
}
}
Hope you help me out soon.
Regards.