0

I'm very new to Android Studio and I'm building an app that has a sidebar with icons that lead to fragments. After following a couple of tutorials, the sidebar is implemented and the icons each lead to a fragment. In one of the fragments I'd like to set up a RecyclerView and a CardView with the ability to make new entries and delete them. I tried following Coding in Flow's tutorial here, however, he is implementing it in the MainActivity, not a fragment. I tried putting them into a fragment using the same code up, which appeared to work fine, until he writes
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.example_item, parent);

Is there another way to define this inflator? Or possibly another tutorial I could refer too?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
jaduuuui
  • 101
  • 11

2 Answers2

0

whats wrong with the syntax!? also you should be passing in the context variable in your adapter via the constructor. you can use that context variable instead of parent.getContext() to access all activity methods. if you are confused still maybe pasting the code which is bugging you will help us giving a better explanation. Also you said you have a problem with your recycler and cardview, probably you mean to say that you cant access the recyclerview or cardview using findViewById? If that is the case you can access them using the view object. Example:

View view =  LayoutInflater.from(parent.getContext()).inflate(R.layout.example_item, parent);
RecyclerView recyclerview = view.findViewById(R.id.recycler);

Sujoy Datta
  • 36
  • 1
  • 4
0

Set attach to root parameter to false Inflate your view as below

View view =  LayoutInflater.from(parent.getContext()).inflate(R.layout.example_item, parent,false);
Alireza Bideli
  • 834
  • 2
  • 9
  • 31