【发布时间】:2020-07-20 05:52:40
【问题描述】:
我遇到了一个问题,我创建了一个片段,没有任何问题,但片段仍然没有打开。这是我的片段:
class PhotoGallery extends Fragment {
RecyclerView recyclerView;
PhotoGalleryAdapter photoGalleryAdapter;
PlaceViewmodel placeViewmodel;
Observer<List<photo_n>> galleryobserver;
@Override
public View onCreateView(LayoutInflater infla, ViewGroup parent, Bundle savd)
{
View verti=infla.inflate(R.layout.photoviewergallery,parent,false);
placeViewmodel = new ViewModelProvider(getActivity()).get(PlaceViewmodel.class);
recyclerView=verti.findViewById(R.id.gridrecycler);
galleryobserver=new Observer<List<photo_n>>() {
@Override
public void onChanged(List<photo_n> photo_ns) {
ArrayList<photo_n> photo_ns1=new ArrayList<photo_n>();
for(photo_n photo:photo_ns)
{
photo_ns1.add(photo);
}
if(photoGalleryAdapter==null)
{
photoGalleryAdapter=new PhotoGalleryAdapter(getActivity(),photo_ns1);
recyclerView.setAdapter(photoGalleryAdapter);
}
else
{
photoGalleryAdapter.setPhotoList(photo_ns1);
}
}
};
placeViewmodel.chosenImages.observe(getViewLifecycleOwner(),galleryobserver);
if(photoGalleryAdapter==null)
{
photoGalleryAdapter=new PhotoGalleryAdapter(getActivity(),new ArrayList<photo_n>());
recyclerView.setAdapter(photoGalleryAdapter);
}
return verti;
}
}
我什至没有重写构造函数,所以它不应该出现以下问题。但它仍然如此,我已经搜索了堆栈溢出的所有问题但仍然没有得到答案。这里有什么问题?
【问题讨论】:
标签: android android-fragments android-navigation