2 回答

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊
您需要retrievetasks()
在初始化適配器后調(diào)用方法。這是導(dǎo)致問題的原因
adapter = new RecyclerAdapter(numofitems); retrievetasks();

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊
in adapteryourretrieveTasks與您初始化的不同。您正在初始化一個(gè)本地實(shí)例,該實(shí)例超出了您的方法范圍retrieveTasks。大概你在片段中有一個(gè)屬性adapter已經(jīng)命名,所以你可以只刪除本地實(shí)例來初始化正確的:
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_recents, container, false);
RecyclerAdapter adapter; // <- DELETE THIS
db = NotesDatabase.createdb(getContext());
adapter = new RecyclerAdapter(numofitems);
}
希望有幫助!
添加回答
舉報(bào)