I am not getting the problem that why it is showing in the fragment: this is the code. The problem is occurring due to return statement we are using in inflator.
public class Information extends Fragment {
private RecyclerView deleteNoticeRecyler;
private ArrayList<AlertData> list;
private AlertsAdapter adapter;
private DatabaseReference reference;
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public Information() {
// Required empty public constructor
}
public static Information newInstance(String param1, String param2) {
Information fragment = new Information();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_information, container, false);
deleteNoticeRecyler = getView().findViewById(R.id.deleteNoticeRecycler);
reference= FirebaseDatabase.getInstance().getReference().child("Notice");
deleteNoticeRecyler.setLayoutManager(new LinearLayoutManager(getContext()));
deleteNoticeRecyler.setHasFixedSize(true);
getAlerts();
return null;
}
private void getAlerts(){
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
list = new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
AlertData data = snapshot.getValue(AlertData.class);
list.add(data);
}
adapter = new AlertsAdapter(getContext(),list);
adapter.notifyDataSetChanged();
deleteNoticeRecyler.setAdapter(adapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(getContext(),databaseError.getMessage() ,Toast.LENGTH_SHORT).show();
}
});
}
}
picture of my issue
Because of this same problem my other my other problems related to findViewbyid is also not working.