我尝试过谷歌的教程,但事情并没有成功。我在RecyclerViewAdapter中遇到错误。
错误如下 RecyclerViewAdapter。 (在第9行评论)
@Override
public void onBindViewHolder(final RecyclerViewHolder holder, final int position) {
int viewType = getItemViewType(position);
switch (viewType){
case AD_VIEW_TYPE:
NativeExpressAdViewHolder nativeExpressHolder = (NativeExpressAdViewHolder)holder;
NativeExpressAdView adView = (NativeExpressAdView)arrayList.get(Position); //Inconvertible types; cannot cast 'app.modals.cardSetterGetter' to 'com.google.android.gms.ads.NativeExpressAdView
ViewGroup adCardView = (ViewGroup)nativeExpressHolder.itemView;
adCardView.removeAllViews();
if(adView.getParent() != null){
((ViewGroup)adView.getParent()).removeView(adView);
}
adCardView.addView(adView);
break;
case MENU_ITEM_VIEW_TYPE:
default:
String card_image;
CardSetterGetter cardSetterGetter;
cardSetterGetter = arrayList.get(position);
card_image = constants.SERVERIP.concat(cardSetterGetter.getImageurl());
holder.cardSetterGetter = cardSetterGetter;
holder.title.setText(cardSetterGetter.getImagetitle()); //set title
cardSetterGetter.getTag();
PointF focusPoint = new PointF(0.5f, 0f);
// your app populates the focus point
holder.image // set image
.getHierarchy()
.setActualImageFocusPoint(focusPoint);
holder.image.setImageURI(Uri.parse(card_image));
}
}
答案 0 :(得分:1)
您不应将视图添加到listItems
。
NativeExpressAdViewHolder
包含项目,而非视图。
RecyclerViewHolder
应扩展holder.getPosition()
。
NativeExpressAdView
是一个位置,而不是adView。它无法转换为private final List<Object> mRecyclerViewItems;
。
如果您仍想在项目列表中保留adView,则应更改itemsList的类型,如示例中所述。 List<app.appname.CardSetterGetter>
不是testView : Html Msg
testView =
div [] [
button [onClick TestAction] [text "Test Action"]
]