我使用fragment运行recycleView但包含错误。 似乎适配器中存在错误。 这是一个片段。我在这里调用ReadRss类。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootViewss = inflater.inflate(R.layout.fragmentinspirasibisnis,container,false);
recyclerView = (RecyclerView)rootViewss.findViewById(R.id.recycleview);
ReadRss readRss = new ReadRss(getActivity(),recyclerView);
readRss.execute();
return rootViewss;
}
我在这个ReadRss文件中调用适配器
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
progressDialog.dismiss();
MyAdapter adapter = new MyAdapter(context,feedItems);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
recyclerView.addItemDecoration(new VerticalSpace(4));
recyclerView.setAdapter(adapter);
}
和这个适配器文件。也许在观众中可能出现错误。
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
ArrayList<FeedItem>feedItems;
Context context;
public MyAdapter (Context context, ArrayList<FeedItem> feedItems){
this.feedItems = feedItems;
this.context = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.custum_new_rows_item,parent,false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
final FeedItem current = feedItems.get(position);
holder.title.setText(current.getTitle());
holder.date.setText(current.getPubDate());
holder.description.setText(current.getDescription());
Picasso.with(context).load(current.getThumbnailUrl()).into(holder.Thumbnails);
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(context,NewDetail.class);
intent.putExtra("Link",current.getLink());
context.startActivity(intent);
}
});}
@Override
public int getItemCount() {
return feedItems.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView title , date, description;
ImageView Thumbnails;
CardView cardView;
public MyViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title_text);
date = (TextView) itemView.findViewById(R.id.date_text);
description = (TextView) itemView.findViewById(R.id.description_text);
Thumbnails = (ImageView) itemView.findViewById(R.id.test);
cardView = (CardView) itemView.findViewById(R.id.cardview);
}
}}
我有这样的错误
Failure getting entry for 0x7f020061 (t=1 e=97) in package 0 (error -75)
08-18 01:34:33.817 2355-2355/com.jdev.anonymous.hahaapp D/AndroidRuntime: Shutting down VM
08-18 01:34:33.817 2355-2355/com.jdev.anonymous.hahaapp W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xaf79bb20)
08-18 01:34:33.857 2355-2355/com.jdev.anonymous.hahaapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.jdev.anonymous.hahaapp, PID: 2355
android.view.InflateException: Binary XML file line #47: Error inflating class ImageView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.jdev.anonymous.hahaapp.MyAdapter.onCreateViewHolder(MyAdapter.java:29)
at com.jdev.anonymous.hahaapp.MyAdapter.onCreateViewHolder(MyAdapter.java:20)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2625)
at android.view.View.measure(View.java:16497)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1226)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.widget.ScrollView.onMeasure(ScrollView.java:326)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1170)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:733)
at android.view.View.measure(View.java:16497)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1075)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)