#java #android-recyclerview
#java #android-recyclerview
Вопрос:
public class Near_By_Places_Adapter extends RecyclerView.Adapter<Near_By_Places_Adapter.ViewHolder> {
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == 1) {
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams attributLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
attributLayoutParams.gravity = Gravity.CENTER;
linearLayout.setLayoutParams(attributLayoutParams);
linearLayout.setGravity(Gravity.CENTER);
AdView adView = new AdView(getActivity());
adView.setAdUnitId(getString(R.string.banner_ad_unit_id));
adView.setAdSize(AdSize.SMART_BANNER);
adView.loadAd(new AdRequest.Builder().build());
linearLayout.addView(adView);
**return new AdviewViewHolder(linearLayout);**
} else {
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.grid_single_row, parent, false));
}
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
if (holder.getItemViewType() == 1)
return;
if (holder.getItemViewType() == 2) {
Picasso.get().load(list.get(position).id).fit().into(holder.IvImg);
Picasso.get().load(list.get(position).id1).fit().into(holder.IvImg1);
Picasso.get().load(list.get(position).id2).fit().into(holder.IvImg2);
}
}
@Override
public int getItemViewType(int position) {
if (list.get(position).text.equals("admob") amp;amp;
list.get(position).text1.equals("admob") amp;amp;
list.get(position).text2.equals("admob")) {
return 1;
} else
return 2;
}
@Override
public int getItemCount() {
return list.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
ImageView IvImg, IvImg1, IvImg2;
ViewHolder(View itemView) {
super(itemView);
IvImg = itemView.findViewById(R.id.tpyeicon_new);
IvImg1 = itemView.findViewById(R.id.tpyeicon_new1);
IvImg2 = itemView.findViewById(R.id.tpyeicon_new2);
IvImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (!Utils.isNetworkAvailable(context)) {
Toast.makeText(context, "No Internet Connection", Toast.LENGTH_SHORT).show();
return;
}
position = getAdapterPosition();
if (mInterstitialAd != null amp;amp; mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
onClickListener();
}
} catch (Exception ignored) {
}
}
});
IvImg1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (!Utils.isNetworkAvailable(context)) {
Toast.makeText(context, "No Internet Connection", Toast.LENGTH_SHORT).show();
return;
}
position = getAdapterPosition();
if (mInterstitialAd != null amp;amp; mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
onClickListener();
}
} catch (Exception ignored) {
}
}
});
IvImg2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (!Utils.isNetworkAvailable(context)) {
Toast.makeText(context, "No Internet Connection", Toast.LENGTH_SHORT).show();
return;
}
position = getAdapterPosition();
if (mInterstitialAd != null amp;amp; mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
onClickListener();
}
} catch (Exception ignored) {
}
}
});
}
}
class AdviewViewHolder extends RecyclerView.ViewHolder {
AdviewViewHolder(View itemView) {
super(itemView);
}
}
}
В этой строке отображается ошибка
верните новый AdviewViewHolder(LinearLayout);
Ошибка:
Near_By_Places_Adapter adapter class in fragement
incompatible types.
Required:
com.example.engr.Fragments.Near_By_Places_Fragment.Near_By_Places_Adapter.ViewHolder
Found:
com.example.engr.Fragments.Near_By_Places_Fragment.Near_By_Places_Adapter.AdviewViewHolderstrong text