I’m getting a cannot resolve symbol RecyclerView error. When I press (alt + enter) there are a list of options but the text never instructed me to choose either. My question is am I missing something in my code. I did the fragment_crime_list.xml correctly. This is what I have up to this point, although I will continue on with the code hoping things will come together.
public class CrimeListFragment extends Fragment
{
/Modify CrimeListFragment to use this layout file and to find the
RecyclerView in the layout file.
------------------------------------------------------------------
Listing 8.16 - Setting up the view for CrimeListFragment/
private RecyclerView mCrimeRecyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_crime_list, container, false);
mCrimeRecyclerView = (RecyclerView) view.findViewById(R.id.crime_recycler_view);
mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}//end of onCreate
//Listing 8.17 the beginnings of a ViewHolder
private class CrimeHolder extends RecyclerView.ViewHolder
{
public CrimeHolder(LayoutInflater inflater, ViewGroup parent)
{
super(inflater.inflate(R.layout.list_item_crime, parent, false));
}//end of CrimeHolder()method
}//end of viewHolder
public class CrimeListFragment extends Fragment
{
/Modify CrimeListFragment to use this layout file and to find the
RecyclerView in the layout file.
------------------------------------------------------------------
Listing 8.16 - Setting up the view for CrimeListFragment/
private RecyclerView mCrimeRecyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_crime_list, container, false);
mCrimeRecyclerView = (RecyclerView) view.findViewById(R.id.crime_recycler_view);
mCrimeRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}//end of onCreate
//Listing 8.17 the beginnings of a ViewHolder
private class CrimeHolder extends RecyclerView.ViewHolder
{
public CrimeHolder(LayoutInflater inflater, ViewGroup parent)
{
super(inflater.inflate(R.layout.list_item_crime, parent, false));
}//end of CrimeHolder()method
}//end of viewHolder
//8.18 the beginnings of an adapter
private class CrimeAdapter extends RecyclerView.Adapter<CrimeHolder>
{}//incomplete
if you get a error for the RecyclerView. I think, you can check first the gradle you added the recycleview in project. And second is that, you should check the layout in the xml file. You must sure added correctly to recyclerview. I think, you don’t get error after you completed two condition. If you get, you should compare verison of recyclerview with the completeSdk version in gradle.