我有一个打开新意图的应用程序。新意图在数据库中插入一些行,然后 finish(); 它并返回到第一个屏幕,数据应该已经用新行刷新了。我的代码在执行时不起作用,但在调试时起作用……所以也许某处有些滞后……也许?如何等待查询完成?这是我的代码:在第一个屏幕上:设置适配器和 onResume@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { v= inflater.inflate(R.layout.filters_fragment,container,false); createFragmentWidgets(); myrecyclerview = (RecyclerView) v.findViewById(R.id.contact_recycleview); recyclerAdapter = new RecyclerViewAdapterFilters(getContext(), lstFilters); myrecyclerview.setLayoutManager(new LinearLayoutManager((getActivity()))); myrecyclerview.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL)); myrecyclerview.setAdapter(recyclerAdapter); return v;}@Overridepublic void onResume(){ // After a pause OR at startup super.onResume(); lstFilters = mydb.getAllFilters("BL"); recyclerAdapter.notifyDataSetChanged();}DB 类上的 getAllFilters 方法public List<Filter> getAllFilters(String type) { List<Filter> lstFilter = new ArrayList<>(); //hp = new HashMap(); SQLiteDatabase db = this.getReadableDatabase(); Cursor res = db.rawQuery( "select * from " + FILTERS_TABLE_NAME+" where type='"+type+"'", null ); res.moveToFirst(); while(res.isAfterLast() == false){ lstFilter.add(new Filter (res.getInt(res.getColumnIndex(FILTERS_COLUMN_ID)), res.getString(res.getColumnIndex(FILTERS_COLUMN_NAME)), res.getString(res.getColumnIndex(FILTERS_COLUMN_NUMBER)), res.getString(res.getColumnIndex(FILTERS_COLUMN_PHOTO)), res.getString(res.getColumnIndex(FILTERS_COLUMN_TYPE)))); res.moveToNext(); } res.close(); db.close(); return lstFilter;}有任何想法吗?
添加回答
举报
0/150
提交
取消