Room多表查询不能嵌套
WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getFailedProjects().observe(TrainFragment.this, new Observer<List<FailedProj_select>>() { @Override public void onChanged(List<FailedProj_select> failedProj_selects) { for (FailedProj_select f : failedProj_selects) { item_id += f.getScore_deducting(); Log.i(TAG, "onChanged: "+f.toString()); Toast.makeText(getActivity().getApplicationContext(),"得分"+item_id,Toast.LENGTH_SHORT).show(); } } });
像这种的会重复查多次
正确的写法如下:两段代码平行分开不能嵌套
WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getSubject(1).observe(this, new Observer<Integer>() { @Override public void onChanged(Integer integers) { Log.i(TAG, "onChanged: "+integers.intValue()); item_id = 0; } }); WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getFailedProjects().observe(TrainFragment.this, new Observer<List<FailedProj_select>>() { @Override public void onChanged(List<FailedProj_select> failedProj_selects) { for (FailedProj_select f : failedProj_selects) { item_id += f.getScore_deducting(); Log.i(TAG, "onChanged: "+f.toString()); Toast.makeText(getActivity().getApplicationContext(),"得分"+item_id,Toast.LENGTH_SHORT).show(); } } });
Dana.Lee
To:Dana_Lee1016@126.com