我正在尝试将我的适配器与recycleview关联。错误发生在initializeDisplayContent()方法中。这是我的代码
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class AnnouncementsFragment extends Fragment {
View rootView;
private AnnouncementRecyclerAdapter mAnnouncementRecyclerAdapter;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_announcements, container, false);
return rootView;
}
private void initializeDisplayContent() {
final RecyclerView recyclerAnnouncements = (RecyclerView) rootView.findViewById(R.id.list_announcements);
final LinearLayoutManager announcementsLayoutManager = new LinearLayoutManager(getContext());
recyclerAnnouncements.setLayoutManager(announcementsLayoutManager);
List<Announcement> announcementsList = DataManager.getInstance().getAnnouncements();
}
}
我有一个公告类,其中包含两个项目的getter和setter:
public class Announcement {
private int id;
private String announcementTitleText, announcementDetailsText;
public Announcement(int id, String announcementTitleText, String announcementDetailsText) {
this.id = id;
this.announcementTitleText = announcementTitleText;
this.announcementDetailsText = announcementDetailsText;
}
public int getId() {
return id;
}
public void setId() {
this.id =id;
}