how do I resolve E/RecyclerView: No adapter attached; skipping layout? [duplicate] - android

This question already has answers here:
"No adapter attached; skipping layout" on a fragment
(1 answer)
E/RecyclerView: No adapter attached; skipping layout (Using FRAGMENTS)
(2 answers)
recyclerview No adapter attached; skipping layout
(38 answers)
Closed 2 years ago.
I am developing an app with fragments and recycler view with firebase database. I want the app to fetch data from database and display it in the fragment layout. I pretty much think that my code is fine and should work properly.
I get the error log E/RecyclerView: No adapter attached; skipping layout
I tried everything out there in other questions, forums.
This is my home.java code :
public class home extends Fragment {
private OnFragmentInteractionListener mListener;
public home() {
}
// TODO: Rename and change types and number of parameters
public static home newInstance() {
home fragment = new home();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
//to recycler view.
private RecyclerView recyclerView;
public View view;
private ArrayList<Model> listItem;
ViewAdapter Vadapter;
DatabaseReference dbRef;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_home, container,false);
recyclerView = view.findViewById(R.id.carDetailsContainer);
listItem = new ArrayList<Model>();
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
dbRef = FirebaseDatabase.getInstance().getReference().child("Cars");
Vadapter = new ViewAdapter(getContext(),listItem);
recyclerView.setAdapter(Vadapter);
return inflater.inflate(R.layout.fragment_home, container, false);
}
#Override
public void onStart() {
super.onStart();
ValueEventListener valueEventListener = new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren())
{
Model model = new Model(ds.child("Name").getValue().toString(),ds.child("Milege").getValue().toString(),ds.child("Fuel").getValue().toString(),ds.child("Transmission").getValue().toString(),ds.child("Rate").getValue().toString());
listItem.add(model);
}
Vadapter = new ViewAdapter(getContext(),listItem);
recyclerView.setAdapter(Vadapter);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
};
dbRef.addValueEventListener(valueEventListener);
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
}
my Adapter class:
public class ViewAdapter extends RecyclerView.Adapter<ViewAdapter.MyViewHolder> {
DatabaseReference ref;
FirebaseDatabase fbRref;
Context context;
ArrayList<Model> model;
public ViewAdapter(Context c, ArrayList<Model> listItems)
{
this.context = c;
this.model = listItems;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.car_details, parent, false);
fbRref = FirebaseDatabase.getInstance();
ref = fbRref.getReference();
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
holder.carName.setText(model.get(position).getmCarName());
holder.seatingCapacity.setText(model.get(position).getmSeatingCapacity());
}
#Override
public int getItemCount() {
return model.size();
}
class MyViewHolder extends RecyclerView.ViewHolder
{
public TextView carName,seatingCapacity;
public MyViewHolder(#NonNull View itemView)
{
super(itemView);
carName = itemView.findViewById(R.id.car_name);
seatingCapacity = itemView.findViewById(R.id.seating_capacity);
}
}
}
I am stuck very badly at this.
Thanks in advance.

Try Changing
return inflater.inflate(R.layout.fragment_home, container, false);
to
return view;

You should move the initialization of your RecylcerView in onViewCreated instead of onCreateView, look at this answer

Related

E/RecyclerView: No adapter attached; skipping layout on recyclerview inside fragment

I have "E/RecyclerView: No adapter attached; skipping layout" error message.
I have recycleView inside fragment so I must have done something wrong on fragment1.java.
here is the code. I set adapter on the code as you can see, but I am getting this error. Any help would be appreciated. Thank you.
public class Fragment1 extends Fragment {
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private RecyclerView.LayoutManager layoutManager;
private ArrayList<Bible> arrayList;
private FirebaseDatabase database;
private DatabaseReference databaseReference;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment1, container, false);
recyclerView = rootView.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
//GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 2);
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
arrayList = new ArrayList<>();
database = FirebaseDatabase.getInstance();
databaseReference = database.getReference("Bible");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
arrayList.clear();
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Bible bible = snapshot.getValue(Bible.class);
arrayList.add(bible);
}
adapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Log.e("fragment1", String.valueOf(databaseError.toException()));//에러문 출력
}
});
adapter = new BibleAdapter(arrayList, getContext());
recyclerView.setAdapter(adapter);
return rootView;
}
}
public class BibleAdapter extends RecyclerView.Adapter {
private ArrayList<Bible> arrayList;
private Context context;
private OnVerseItemClickListener listener;
public BibleAdapter(ArrayList<Bible> arrayList, Context context) {
this.arrayList = arrayList;
this.context = context;
}
public void setOnItemClickListener(OnVerseItemClickListener listener){
this.listener = listener;
}
#NonNull
#Override
public BibleAdapter.BibleViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.verse_item, parent, false);
BibleViewHolder holder = new BibleViewHolder(view, listener);
return holder;
}
#Override
public void onBindViewHolder(#NonNull BibleAdapter.BibleViewHolder holder, int position) {
Glide.with(holder.imageView)
.load(arrayList.get(position).getImage())
.into(holder.imageView);
holder.bibleType.setText(arrayList.get(position).getBibleType());
holder.keysentance.setText(arrayList.get(position).getKeysentance());
holder.verse.setText(arrayList.get(position).getVerse());
}
#Override
public int getItemCount() {
return (arrayList!=null? arrayList.size():0);
}
public class BibleViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
TextView bibleType;
TextView verse;
TextView keysentance;
public BibleViewHolder(#NonNull View itemView, final OnVerseItemClickListener listener) {
super(itemView);
this.imageView = itemView.findViewById(R.id.imageView);
this.bibleType = itemView.findViewById(R.id.bibleType);
this.keysentance = itemView.findViewById(R.id.keysentance);
this.verse = itemView.findViewById(R.id.verse);
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int position = getAdapterPosition();
if(listener != null){
listener.onItemClick(BibleViewHolder.this, v, position);
}
}
});
}
}
}
in your code you have create adapter with empty arrayList, but never after that you update the list.
in adapter create swapData() method and call it when you have to refresh data or have refreshed data, in your case you will get it in onDataChange().
And also define adapter before adding listener:
adapter = new BibleAdapter(arrayList, getContext());
recyclerView.setAdapter(adapter);
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
arrayList.clear();
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Bible bible = snapshot.getValue(Bible.class);
arrayList.add(bible);
}
adapter.swapData(arrayList);
//adapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Log.e("fragment1", String.valueOf(databaseError.toException()));//에러문 출력
}
});
in adapter class create method as:
public void swapData(ArrayList<Bible> filtersList) {
if (filtersList != null) {
this.arrayList.clear();
this.arrayList.addAll(filtersList);
notifyDataSetChanged();
}
}

RecyclerView: No Adapter attached; Skipping layout in fragment

I found two similar questions but none of them worked. I am using fragment and RecyclerViews. The console displays the error
E/RecyclerView: No adapter attached; skipping layout
https://i.stack.imgur.com/dxk8y.png Adapter
https://i.stack.imgur.com/0J2io.png Fragment
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.listkos, null);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
User user = entries.get(position);
holder.textViewTitle.setText(entries.get(position).getnmkos());
holder.textViewShortDesc.setText(entries.get(position).getHp());
}
#Override
public int getItemCount() {
return entries.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView textViewTitle, textViewShortDesc;
ImageView imageView;
public MyViewHolder(View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.tvnm);
textViewShortDesc = itemView.findViewById(R.id.tvhp);
}
}
}
this fragment
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_beranda, container, false);
database = FirebaseDatabase.getInstance().getReference("Users");
firebaseAuth = FirebaseAuth.getInstance();
firebaseUser = firebaseAuth.getCurrentUser();
re = (RecyclerView) view.findViewById(R.id.recyle_buka);
rvLayoutManager = new LinearLayoutManager(getActivity());
re.setLayoutManager(rvLayoutManager);
loadEntries();
return view;
}
private void loadEntries(){
database.child("Users").child(firebaseUser.getUid()).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
entries= new ArrayList<>();
for (DataSnapshot noteDataSnapshot:dataSnapshot.getChildren()){
User user=noteDataSnapshot.getValue(User.class);
user.setKey(noteDataSnapshot.getKey());
entries.add(user);
}
rvAdapter = new RvAdapter(entries) ;// This is still empty, probably
re.setAdapter(rvAdapter);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Log.w("LogFragment", "loadLog:onCancelled", databaseError.toException());
}
});
}
}
still not working guys
/*It looks like your post is mostly code; please add some more detail */
You must be create a Linear Layout manager. You must be set adapter to the recyclerview.
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
re.setLayoutManager(linearLayoutManager);
YourAdapter yourAdapter = new YourAdapter(list);
re.setAdapter(yourAdapter);
E/RecyclerView: No adapter attached; skipping layout
It means you haven't attached the adapter to your RecyclerView. So, you need to initialized your RecyclerView with an empty adapter. Something like this:
re = (RecyclerView) view.findViewById(R.id.recyle_buka);
rvLayoutManager = new LinearLayoutManager(getActivity());
re.setLayoutManager(rvLayoutManager);
// initialize empty adapter
entries= new ArrayList<>();
rvAdapter = new RvAdapter(entries);
re.setAdapter(rvAdapter);
Then, whenever you need to reload and refresh the RecyclerView, you should not doing this:
private void loadEntries(){
...
entries= new ArrayList<>();
for (DataSnapshot noteDataSnapshot:dataSnapshot.getChildren()){
User user=noteDataSnapshot.getValue(User.class);
user.setKey(noteDataSnapshot.getKey());
entries.add(user);
}
// DON'T DO THIS!
rvAdapter = new RvAdapter(entries) ;
re.setAdapter(rvAdapter);
}
because it resetting your adapter with a new Adapter.
What you need is refreshing the list and notifying the adapter for data changes.
First, add the following method to your Adapter to reload the list:
public void swap(List<User> list) {
entries.clear();
entries.addAll(list);
notifyDataSetChanged();
}
Then add it to your loadEntries(). Something like this:
private void loadEntries() {
...
List<User> newEntries = new ArrayList<>();
for (DataSnapshot noteDataSnapshot:dataSnapshot.getChildren()){
User user=noteDataSnapshot.getValue(User.class);
user.setKey(noteDataSnapshot.getKey());
newEntries.add(user);
}
rvAdapter.swap(newEntries);
}
This happen because you didn't set layout manager to Recyclerview.
Refer below example.
Initialize recyclerview
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
Initialize your adapter class
mAdapter = new MoviesAdapter(movieList);
now set layout manager to recyleview
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);

Fragment isn't displaying RecyclerView [duplicate]

This question already has answers here:
How to implement Firebase Recycler Adapter in newer version of Android 3.1 and higher?
(2 answers)
Closed 3 years ago.
So, I watched some tutorial on how to do the RecyclerView mainly this. I tweaked the code to fit my needs. But when i try to ran it, the RecyclerView isn't displaying on the fragment. My guess is the problem lies in adapter and viewholder part, because i'm not sure how to implement it yet. Can anyone help me?
The Fragment.java
public class JobListFragment extends Fragment {
RecyclerView mRecyclerView;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
public JobListFragment(){
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
((MainHomeActivity)getActivity()).setActionBarTitle("Job List");
View view = inflater.inflate(R.layout.fragment_job_list, container, false);
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference().child("Data");
mRecyclerView = view.findViewById(R.id.recycleView);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mRecyclerView.setHasFixedSize(true);
return view;
}
#Override
public void onStart() {
super.onStart();
FirebaseRecyclerOptions<Model> options =
new FirebaseRecyclerOptions.Builder<Model>()
.setQuery(databaseReference, Model.class).build();
FirebaseRecyclerAdapter adapter = new FirebaseRecyclerAdapter<Model, ViewHolder>(options) {
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.row, viewGroup, false);
return new ViewHolder(view);
}
#Override
protected void onBindViewHolder(#NonNull ViewHolder holder, int position, #NonNull Model model) {
holder.setDetails(model.getTitlept(), model.getDescpt(), model.getImagept());
}
};
mRecyclerView.setAdapter(adapter);
}
}
ViewHolder.java
public class ViewHolder extends RecyclerView.ViewHolder {
View mView;
public ViewHolder(View itemView){
super(itemView);
mView = itemView;
}
public void setDetails(String title, String description, String image){
TextView mTitleTv = mView.findViewById(R.id.rTitleTv);
TextView mDescTv = mView.findViewById(R.id.rDescIv);
ImageView mImageIv = mView.findViewById(R.id.rImageIv);
mTitleTv.setText(title);
mDescTv.setText(description);
Picasso.get().load(image).into(mImageIv);
}
}
Model.java
public class Model {
String titlept, imagept, descpt;
public Model(){}
public String getTitlept() {
return titlept;
}
public void setTitlept(String titlept) {
this.titlept = titlept;
}
public String getImagept() {
return imagept;
}
public void setImagept(String imagept) {
this.imagept = imagept;
}
public String getDescpt() {
return descpt;
}
public void setDescpt(String descpt) {
this.descpt = descpt;
}
}
Can you write the problem a little bit more clearly? Picture not displayed? #AdhityoPutro

Displaying RecyclerView into fragment

I've got methods:
private void initImageBitmaps() {
mImageUrls.add("imageUrl");
mNames.add("abcd");
initRecyclerView();
}
private void initRecyclerView() {
Log.d(TAG, "initRecyclerView: init recyclerview.");
RecyclerView recyclerView = findViewById(R.id.recyclerv_view);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, mNames, mImageUrls);
recyclerView.setAdapter(adapter);
//recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
}
Which add images to my recyclerview.
If it was in activity I would call initImageBitmaps() inside OnCreate. Unfortunately I have to use it in fragment and the question is: how to implement these methods to class which extends Fragment? Of course everything will be displayed into RecyclerView with recycler_view id in xml.
EDIT:
My Adapter:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>{
private static final String TAG = "RecyclerViewAdapter";
private ArrayList<String> mImageNames = new ArrayList<>();
private ArrayList<String> mImages = new ArrayList<>();
private Context mContext;
public RecyclerViewAdapter(WallpapersFragment context, ArrayList<String> imageNames, ArrayList<String> images ) {
mImageNames = imageNames;
mImages = images;
mContext = context;
//Rquired is android.content.context and found is WallpapersFragment from my project
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_listitem, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(ViewHolder holder, final int position) {
Log.d(TAG, "onBindViewHolder: called.");
Glide.with(mContext)
.asBitmap()
.load(mImages.get(position))
.into(holder.image);
holder.imageName.setText(mImageNames.get(position));
holder.parentLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(mContext, GalleryActivity.class);
intent.putExtra("image_url", mImages.get(position));
intent.putExtra("image_name", mImageNames.get(position));
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
return mImageNames.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
ImageView image;
TextView imageName;
RelativeLayout parentLayout;
public ViewHolder(View itemView) {
super(itemView);
image = itemView.findViewById(R.id.image);
imageName = itemView.findViewById(R.id.image_name);
parentLayout = itemView.findViewById(R.id.parent_layout);
}
}
}
It compiles only when I comment mContext = context; in adapter. Then the error is:
java.lang.NullPointerException: You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).
There is an onCreate() method in the Fragment class, but that method is different from activity's onCreate().
public static class ExampleFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.example_fragment, container, false);
}
#Override
public void onViewCreated (View view, Bundle savedInstanceState) {
initRecyclerView();
}
}
Read more about fragments here: Fragments
initRecyclerView(view);
And then:
recyclerView = view.findViewById(R.id.recyclerv_view);
You can initialize your recycler view in following lifecycle callback:
onViewCreated()
and can also populate data method here like
initRecyclerView()
initImageBitmaps()
and for data refresh you can call notifyDatasetChanged() on adapter.
try this...
public class ExampleFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view= inflater.inflate(R.layout.example_fragment, container, false);
initImageBitmaps(view);
return view;
}
private void initImageBitmaps(View view) {
mImageUrls.add("imageUrl");
mNames.add("abcd");
initRecyclerView(View view);
}
private void initRecyclerView(View view) {
Log.d(TAG, "initRecyclerView: init recyclerview.");
RecyclerView recyclerView = view.findViewById(R.id.recyclerv_view); // init recyclerview
GridLayoutManager layoutManager = new GridLayoutManager(getContext(), 2);// declare layoutmanager
recyclerView.setLayoutManager(layoutManager); // set layoutmanager
RecyclerViewAdapter adapter = new RecyclerViewAdapter(getContext(), mNames, mImageUrls); // init adapter
recyclerView.setAdapter(adapter); // set adapter in recyclerveiw
}
EDIT
Replace WallpapersFragment with Context in adapter
public RecyclerViewAdapter(Context context, ArrayList<String> imageNames, ArrayList<String> images ) {
mImageNames = imageNames;
mImages = images;
mContext = context;
//Rquired is android.content.context and found is WallpapersFragment from my project
}

RecyclerView: No adapter attached; skipping layout Error

I have referred quite few posts regarding this error but none of them could able to solve my issue. I have a fragment where I get my values using retrofit which I have shown below:
public class Tab extends Fragment
{
public String nlink;
public RecyclerView recycler;
public List<Initialise> item;
public Adapter adapter;
public Context mContext;
public Tab(Context mContext)
{
this.mContext=mContext;
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState)
{
View v= inflater.inflate(R.layout.tab_layout,container,false);
item = new ArrayList<>();
recycler=(RecyclerView)v.findViewById(R.id.recycler);
recycler.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(getContext());
llm.setOrientation(LinearLayoutManager.VERTICAL);
recycler.setLayoutManager(llm);
recycler.setItemAnimator(new DefaultItemAnimator());
adapter = new Adapter(item,mContext);
recycler.setAdapter(adapter);
return v;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
Bundle bundle=getArguments();
nlink=bundle.getString("link");
Retrofit adapter = new Retrofit.Builder()
.baseUrl(ItemAdapter.ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
Service Serviceapi = adapter.create(Service.class);
Serviceapi.getitem(nlink).enqueue(new Callback<Item>()
{
#Override
public void onResponse(Call<Item> call, Response<Item> response)
{
for(int i=0;i<response.body().getitems().size();i++)
{
item.add(new Initialise(response.body().getitems().get(i).getTitle(),response.body().getitems().get(i).getDate(),response.body().getitems().get(i).getcount(),response.body().getitems().get(i).getImage()));
}
adapter.notifyDataSetChanged();
}
#Override
public void onFailure(Call<Item> call, Throwable t)
{
}
});
}
}
And the following is my RecyclerView Adapter class:
public class Adapter extends RecyclerView.Adapter<Adapter.Holder>
{
static class Holder extends RecyclerView.ViewHolder
{
CardView cv;
ImageView thum_img;
TextView thum_time;
TextView thum_count;
TextView thum_text;
Holder(View itemView)
{
super(itemView);
cv = (CardView)itemView.findViewById(R.id.cv);
thum_img = (ImageView)itemView.findViewById(R.id.thum_img);
thum_time = (TextView)itemView.findViewById(R.id.thum_time);
thum_count = (TextView)itemView.findViewById(R.id.thum_scount);
thum_text = (TextView)itemView.findViewById(R.id.thum_text);
}
}
private List<Initialise> item;
private Context mContext;
public Adapter(List<Initialise> item, Context mContext)
{
this.item=item;
this.mContext=mContext;
}
#Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType)
{
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_layout, parent, false);
return new Holder(v);
}
#Override
public void onBindViewHolder(Holder holder, int position)
{
holder.thum_text.setText(item.get(position).gettitle());
holder.thum_time.setText(item.get(position).gettime());
holder.thum_count.setText(item.get(position).getcount());
Picasso.with(mContext).load(item.get(position).getstoryImage()).resize(120, 60).into(holder.thum_img);
}
#Override
public int getItemCount()
{
return item.size();
}
}
I'm getting the following error:
E/RecyclerView: No adapter attached; skipping layout
My cardview is not getting displayed and the viewpager is empty. Where am I going wrong ?
Try to edit onCreateViewHolder() method
View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_layout,parent,false);
Holder rcv = new Holder(layoutView,mContext);
return rcv;

Categories

Resources