我不明白为什么它在片段中显示的问题:这是代码。2问题是由于我们在inflator中使用的return语句引起的。
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();
}
});
}
}
我的问题的图片
由于这个问题,我的其他问题,我的其他问题有关的findViewbyid也是不工作。
1条答案
按热度按时间cczfrluj1#
您是否尝试过将return语句放在onCreateView()方法的末尾,return关键字会标记执行端点,因此无法到达。