How to Fix no adapter attached skipping layout in fragment - android

I have added an adapter to my recycler view, the adapter contains the data plist which is an ArrayList populated with firebase data.
I have done this in the onCreateView method in my Fragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_buy, container, false);
recyler = rootView.findViewById(R.id.recycler);
recyler.setHasFixedSize(true);
reference = FirebaseDatabase.getInstance().getReference("Produce");
plist = new ArrayList<>();
adapter = new Produce_RecyclerViewAdapter(rootView.getContext(), plist);
recyler.setAdapter(adapter);
final int count = 0;
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
for (DataSnapshot ds : snapshot.getChildren()) {
Produce produce = ds.getValue(Produce.class);
plist.add(produce);
}
adapter.notifyDataSetChanged();
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
Display();
}
});
return inflater.inflate(R.layout.fragment_buy, container, false);
As far as I can tell there are no errors with my Recycler adapter:
public class Produce_RecyclerViewAdapter extends RecyclerView.Adapter<Produce_RecyclerViewAdapter.ViewHolder>{
private final List<Produce> produce_item;
private final Context context;
public Produce_RecyclerViewAdapter(Context context, ArrayList<Produce> produce_item) {
this.produce_item = produce_item;
this.context = context;
}
#NonNull
#NotNull
#Override
public ViewHolder onCreateViewHolder(#NonNull #NotNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.produce_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull #NotNull ViewHolder holder, int position) {
Produce produce = produce_item.get(position);
holder.ptitle.setText(produce.getPname());
holder.pprice.setText(produce.getPprice());
Picasso.with(context)
.load(produce.getPimg())
.placeholder(R.mipmap.ic_launcher)
.fit()
.centerCrop()
.into(holder.pimage);
}
#Override
public int getItemCount() {
return produce_item.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
ImageView pimage;
TextView ptitle, pprice;
CardView view, addtocart;
public ViewHolder(#NonNull #NotNull View itemView) {
super(itemView);
pimage = itemView.findViewById(R.id.pimage);
ptitle = itemView.findViewById(R.id.ptitle);
pprice = itemView.findViewById(R.id.pprice);
view = itemView.findViewById(R.id.view);
addtocart = itemView.findViewById(R.id.addtocart);
}
}
}
I added the linear layout manager directly to the recycler view:
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="vertical"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
and here is the firebase data:
firebase data
Edit: I checked out recyclerview No adapter attached; skipping layout
and quite a few other answers relating to the problem but either I have already done what they suggested or they are referring to recycler view in an activity and not in a fragment.

The No adapter attached; skipping layout is harmless and overall can be ignored.
Your problem is that you are inflating the view two times. You inflate first and setup everything, throw that way. Inflate it second time and return it without any setup.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_buy, container, false);
/*
* All of the setup
*/
//return inflater.inflate(R.layout.fragment_buy, container, false);
return rootView;
}

Related

Pass parameters in RecycleViewer adapter

In the onCreateViewHolder method of the adapter, I have the oprShown variable that I need to be passed as a parameter.
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.layout_shift_container, parent, false);
GridLayoutManager.LayoutParams lp = (GridLayoutManager.LayoutParams)itemView.getLayoutParams();
lp.width = parent.getMeasuredWidth()/oprShown;
itemView.setLayoutParams(lp);
return new ShiftViewHolder(itemView);
}
The constructor of the adapter is like below:
private Context context;
private List<ShiftModel> shiftModelList;
int oprShown;
public ShiftMapAdapter(Context context, List<ShiftModel> shiftModelList, int oprShown) {
this.context = context;
this.shiftModelList = shiftModelList;
this.oprShown = oprShown;
}
Then I call everything like below:
int operatorShow = 6;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
shiftsViewModel =
ViewModelProviders.of(this).get(ShiftsViewModel.class);
setHasOptionsMenu(true);
View root = inflater.inflate(R.layout.fragment_shifts, container, false);
unbinder = ButterKnife.bind(this, root);
initialize();
shiftsViewModel.getCoworkerList().observe(this, new Observer<List<ShiftModel>>() {
#Override
public void onChanged(List<ShiftModel> shiftModel) {
ShiftMapAdapter shiftMapAdapter = new ShiftMapAdapter(getContext(), shiftModel, operatorShow);
coworker_recycler.setAdapter(shiftMapAdapter);
}
});
return root;
}
All I want to do is to make the width of the recycle view equal to 1/6 of the parent screen. But when I run the code I get this error:
error: constructor ShiftMapAdapter in class ShiftMapAdapter cannot be applied to given types;
required: Context,List,int
found: Context,List
reason: actual and formal argument lists differ in length
Any help, please?
Use getActivity() instead of getContext()
ShiftMapAdapter shiftMapAdapter = new ShiftMapAdapter(getActivity(), shiftModel, operatorShow);
coworker_recycler.setAdapter(shiftMapAdapter);

Can't get FirestoreRecyclerAdapter to show items

I'm updating my app to use Firebase's Firestore database. I'm struggling to get the app to show the data that's been retrieved from the database. The data is retrieved ok, but doesn't show up. By setting breakpoints, I've established that the ViewHolder isn't being bound to the adapter at any point.
The data is being shown in a Fragment. The Fragment layout is (I've taken out irrelevant stuff like padding, sizes etc):
<android.support.constraint.ConstraintLayout
android:id="#+id/layout_charts_list"
tools:context="apppath.fragments.ChartListFragment">
<TextView
android:id="#+id/loading_list"
android:text="#string/loading_my_charts" />
<TextView
android:id="#+id/empty_list"
android:text="#string/my_charts_empty"
android:visibility="gone"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/charts_list" />
</android.support.constraint.ConstraintLayout>
The Fragment code itself is:
public abstract class ChartListFragment extends Fragment {
private FirebaseFirestore mDatabaseRef;
private FirestoreRecyclerAdapter<Chart, ChartViewHolder> mAdapter;
private Query mChartsQuery;
private RecyclerView mRecycler;
public ChartListFragment() {}
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View rootView = inflater.inflate(
R.layout.fragment_charts_list, container, false);
mRecycler = rootView.findViewById(R.id.charts_list);
mRecycler.setHasFixedSize(true);
// Set up Layout Manager, and set Recycler View to use it
LinearLayoutManager mManager = new LinearLayoutManager(getActivity());
mManager.setReverseLayout(true);
mManager.setStackFromEnd(true);
mRecycler.setLayoutManager(mManager);
// Connect to the database, and get the appropriate query (as set in the actual fragment)
mDatabaseRef = FirebaseFirestore.getInstance();
mChartsQuery = getQuery(mDatabaseRef);
// Set up Recycler Adapter
FirestoreRecyclerOptions<Chart> recyclerOptions = new FirestoreRecyclerOptions.Builder<Chart>()
.setQuery(mChartsQuery, Chart.class)
.build();
mAdapter = new ChartListAdapter(recyclerOptions);
// Use Recycler Adapter in RecyclerView
mRecycler.setAdapter(mAdapter);
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Add listener to charts collection, and deal with any changes by re-showing the list
mChartsQuery.addSnapshotListener(new EventListener<QuerySnapshot>() {
#Override
public void onEvent(#Nullable QuerySnapshot queryDocumentSnapshots,
#Nullable FirebaseFirestoreException e) {
if (queryDocumentSnapshots != null && queryDocumentSnapshots.isEmpty()) {
((MainActivity) getActivity()).setPage(1);
mRecycler.setVisibility(View.GONE);
}else {
mRecycler.setVisibility(View.VISIBLE);
}
}
});
}
// HELPER FUNCTIONS
public abstract Query getQuery(FirebaseFirestore databaseReference);
}
ChartListAdapter is as follows:
public class ChartListAdapter
extends FirestoreRecyclerAdapter<Chart, ChartViewHolder> {
public ChartListAdapter(FirestoreRecyclerOptions recyclerOptions) {
super(recyclerOptions);
}
#Override
protected void onBindViewHolder(ChartViewHolder holder, int position, Chart model) {
holder.setChartName(model.getName());
// Bind Chart to ViewHolder
holder.bindToChart(model);
}
#Override
public ChartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_chart, parent, false);
return new ChartViewHolder(view);
}
}
ChartViewHolder:
public class ChartViewHolder extends RecyclerView.ViewHolder {
private TextView chartNameView;
private String chartKey;
public ChartViewHolder(View itemView) {
super(itemView);
chartNameView = itemView.findViewById(R.id.chart_name);
}
public void setChartName(String chartName) {
chartNameView.setText(chartName);
}
public void bindToChart(Chart chart) {
chartKey = chart.getKey();
chartNameView.setText(chart.getName());
}
public String getChartKey() {
return chartKey;
}
}
The ChartListAdapter constructor is called, but onBindViewHolder and onCreateViewHolder are never called, and ChartViewHolder is never accessed at all. Am I missing a line of code? Or doing this completely wrong? I'm not all that familiar with Adapters and RecyclerViews, so I've found it quite hard to get to grips with putting it all together.
For those who came here from Google, set the lifecycle owner on the options so that start/stop listening is called automatically.
FirestoreRecyclerOptions<Chart> recyclerOptions = FirestoreRecyclerOptions.Builder<Chart>()
.setQuery(mChartsQuery, Chart.class)
.setLifecycleOwner(this)
.build();
You need to add the following, to begin listening for data, call the startListening() method. You may want to call this in your onStart() method. Make sure you have finished any authentication necessary to read the data before calling startListening() or your query will fail:
#Override
protected void onStart() {
super.onStart();
adapter.startListening();
}
more info here:
https://github.com/firebase/FirebaseUI-Android/tree/master/firestore

RecyclerView didn't show up

I have faced with a problem that my RecyclerView didn't show up after it gets the data from server side.
When I am trying to debug my code - sometimes it went to DataAdapter class - sometimes not. Unfortunatly, I don't understand why it happends.
I am using the MVP pattern, and maybe I am setting data to adapter wrong.
I'll try to put code here and explain what am I doing.
First of all my card view xml file:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="5dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView android:id="#+id/info_image"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1.0"
android:scaleType="centerCrop"/>
<TextView
android:id="#+id/info_text"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
</android.support.v7.widget.CardView>
Here is my Adapter for Recycler view:
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.ViewHolder> {
private AutoService[] autoServices = new AutoService[]{};
private Context context;
private static final int IMAGE_WIDTH = 120;
private static final int IMAGE_HEIGHT = 60;
//TODO check how to properly set data on view from presenter
public void setAutoServices(AutoService[] autoServices) {
this.autoServices = autoServices;
}
public DataAdapter(Context context) {
this.context = context;
}
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
CardView cardView = (CardView) LayoutInflater.from(parent.getContext()).
inflate(R.layout.auto_service_card_view, parent, false);
return new ViewHolder(cardView);
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
CardView cardView = holder.cardView;
ImageView imageView = (ImageView)cardView.findViewById(R.id.info_image);
Picasso.with(context).load(autoServices[position].getImageURL()).resize(IMAGE_WIDTH, IMAGE_HEIGHT).into(imageView);
TextView textView = (TextView)cardView.findViewById(R.id.info_text);
textView.setText(autoServices[position].getServiceName());
}
#Override
public int getItemCount() {
return autoServices.length;
}
public class ViewHolder extends RecyclerView.ViewHolder{
private CardView cardView;
public ViewHolder(CardView card) {
super(card);
cardView = card;
}
}
}
In my fragment(view) I have a setter which sets the data for adapter.
Date went from presenter which calls data from server side useng rest template.
Here is my presenter:
public class RecyclerViewPresenter implements RecyclerViewContract.Presenter {
private RestTemplate restTemplate;
private RecyclerViewContract.View view;
public RecyclerViewPresenter(RecyclerViewContract.View view){
this.view = view;
new RecyclerViewTask().execute();
}
private class RecyclerViewTask extends AsyncTask<Void, Void, AutoService[]>{
#Override
protected AutoService[] doInBackground(Void... voids) {
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<AutoService[]> autoServiceEntity = restTemplate.getForEntity(URL.getAllAutoServices(), AutoService[].class);
return autoServiceEntity.getBody();
}
#Override
protected void onPostExecute(AutoService[] autoServices) {
view.setAutoServiceListOnAdapter(autoServices);
}
}
}
For some reason when my activity with fragment(RecyclerView) starts - the recyclerView someTimes shows up sometimes not. May be am I setting data for adapter wrong using MVP?
Also I am using the Picasso library - and pictures didn't load from url path, for example URL: https://pbs.twimg.com/profile_images/616076655547682816/6gMRtQyY.jpg .
May be the bproblem in Picasso library ?
Any suggestions please ?
public class RecyclerViewFragment extends Fragment implements RecyclerViewContract.View{
private RecyclerViewContract.Presenter presenter;
private DataAdapter dataAdapter;
public RecyclerViewFragment() {
// Required empty public constructor
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if(presenter == null){
presenter = new RecyclerViewPresenter(this);
}
}
public static RecyclerViewFragment getInstance(){
return new RecyclerViewFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RecyclerView recyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_recycler_view, container, false);
dataAdapter = new DataAdapter(getActivity());
recyclerView.setAdapter(dataAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
return recyclerView;
}
#Override
public void setPresenter(RecyclerViewContract.Presenter presenter) {
this.presenter = presenter;
}
#Override
public void setAutoServiceListOnAdapter(AutoService[] autoServices) {
dataAdapter.setAutoServices(autoServices);
}
Also when I am trying to open activity with recycler view and it didn't shows I have next log:
W/EGL_emulation: eglSurfaceAttrib not implemented
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xe1b01280, error=EGL_SUCCESS
D/OpenGLRenderer: endAllStagingAnimators on 0xeb8d2e80 (RippleDrawable) with handle 0xe1b2dab0
When I am reopen the activity with recycler view and it shows - I have next log:
W/Settings: Setting airplane_mode_on has moved from android.provider.Settings.System to android.provider.Settings.Global, returning read-only value.
D/OpenGLRenderer: endAllStagingAnimators on 0xeb8d2e80 (RippleDrawable) with handle 0xe25165b0
A/libc: Fatal signal 4 (SIGILL), code 2, fault addr 0xf6f1d46e in tid 2539 (16/6gMRtQyY.jpg)
and application crashes after this.
Check my answer.
Try to return proper fragment root viewGroup, not the widget view.
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_recycler_view, container, false);
RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);
dataAdapter = new DataAdapter(getActivity());
recyclerView.setAdapter(dataAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
return view;
}
Edit: I have added dataAdapter.notifyDataSetChanged(); line in place where adapter gets data.
#Override
public void setAutoServiceListOnAdapter(AutoService[] autoServices) {
dataAdapter.setAutoServices(autoServices);
dataAdapter.notifyDataSetChanged();
}

ViewPager stucks while swiping views

I have created a viewpager with tabslayout.Each view of viewpager consists of recyclerview inside fragment.The issue i am having is that when i swipe through the views it stucks while swiping in such a manner that there is no change in view and i have to swipe multiple times in order to change view.It looks that swipe event is not detected by viewpager.However if i comment out below two lines which includes setting adapter then i don't experience such issue and swipe is smooth and fast.
PlanListAdapter mAdapter = new PlanListAdapter(browsePlanModelList, getActivity());
rvBrowsePlanList.setAdapter(mAdapter);
Where am i going wrong and how can i resolve this?
Below is code of fragment and adapter-
public class FullTimeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_browse_plan_list, container, false);
ArrayList<BrowsePlanModel> browsePlanModelList = (ArrayList<BrowsePlanModel>) getArguments().getSerializable(AppConstant.BROWSEPLANlIST);
RecyclerView rvBrowsePlanList = (RecyclerView) view.findViewById(R.id.rvBrowsePlanList);
//rvBrowsePlanList.addItemDecoration(new SimpleDividerIncludingLastItemDecoration(getResources()));
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
rvBrowsePlanList.setLayoutManager(mLayoutManager);
rvBrowsePlanList.setItemAnimator(new DefaultItemAnimator());
if(browsePlanModelList!=null)
{
BrowsePlanListAdapter mAdapter = new BrowsePlanListAdapter(browsePlanModelList, getActivity());
rvBrowsePlanList.setAdapter(mAdapter);
}
return view;
}
}
Adapter
public class PlanListAdapter extends RecyclerView.Adapter<PlanListAdapter.MyViewHolder> {
private List<BrowsePlanModel> planList;
Context mContext;
public PlanListAdapter(List<BrowsePlanModel> planList, Context mContext) {
this.mContext = mContext;
this.planList = planList;
}
#Override
public PlanListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.sffs_item, parent, false);
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(PlanListAdapter.MyViewHolder holder, int position) {
holder.xyz.setText(planList.get(position).getxyx());
holder.abc.setText(planList.get(position).getabc());
}
#Override
public int getItemCount() {
return planList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView xyz, abc;
public MyViewHolder(View itemView) {
super(itemView);
xyz = (TextView) itemView.findViewById(R.id.xyz);
abc = (TextView) itemView.findViewById(R.id.abc);
}
}
}
Use
myViewPager.setOffscreenPageLimit(number of pages in your viewpager minus 1);
If you do not do this, the pages which are not currently visible will be destroyed and will be recreated every time you swipe. This will lead to huge lag if each of those pages is populating a RecyclerView from a database, etc.
It may be happening because of high resolution image. If you use high resolution images then the viewPager will stuck while swiping . Try using low resolution images.

Can't make Fragment with RecyclerView work

I have to create a list inside one of my Fragments but I cannot make recyclerview work, I was searching the internet whole day followed tutorials but could not figure out why its not working
row_item.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/list"
android:name="com.streak.roadpoliceviolations.ViolationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="com.streak.roadpoliceviolations.ViolationFragment"
tools:listitem="#layout/fragment_violation" />
Adapter:
public class ViolationAdapter extends RecyclerView.Adapter<ViolationAdapter.MyViewHolder>{
private LayoutInflater inflater;
List<ViolationItem> data= Collections.emptyList();
public ViolationAdapter(List<ViolationItem> data) {
//inflater = LayoutInflater.from(context);
this.data = data;
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.fragment_violation, parent, false);
MyViewHolder holder = new MyViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(MyViewHolder holder, int position) {
ViolationItem current = data.get(position);
holder.txt1.setText(current.txt1);
holder.txt2.setText(current.txt2);
}
#Override
public int getItemCount() {
return 0;
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView txt1;
TextView txt2;
public MyViewHolder(View itemView) {
super(itemView);
txt1= (TextView) itemView.findViewById(R.id.txt1);
txt2= (TextView) itemView.findViewById(R.id.txt2);
}
}
}
Fragment class
public class ViolationFragment extends Fragment {
private ViolationAdapter adapter;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_violation_list, container, false);
RecyclerView rv = (RecyclerView) view.findViewById(R.id.list);
adapter = new ViolationAdapter(getActivity(),getData());
rv.setAdapter(adapter);
rv.setLayoutManager(new LinearLayoutManager(getActivity()));
return view;
}
public static List<ViolationItem> getData() {
List<ViolationItem> data = new ArrayList<>();
String[] txts1 = {"AAA","BBB","CCC"};
String[] txts2 = {"111","222","333"};
for(int i=0; i<=txts1.length; i++) {
ViolationItem c = new ViolationItem();
c.txt1=txts1[i];
c.txt2=txts2[i];
data.add(c);
}
return data;
}
private List<ViolationItem> createList() {
List<ViolationItem> data = new ArrayList<>();
return data;
}
}
Everything passes without a single warning BUT I cannot place this into the fragment container
In mine activity I'm calling the fragment with the following code
//Initial fragment
ViolationFragment frag = new ViolationFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction() .replace(R.id.frame_container, frag).commit();
Getting this error during the build
Error:(77, 75) error: incompatible types: ViolationFragment cannot be converted to Fragment
And if i change frag initialization Fragment frag = new ViolationFragment();
I get the same error.
How to finally fix this and make the fragment work?!
As I remember you must use support library fragment to make it work. Please check and confirm.

Categories

Resources