Java SQLiteDatabase是同步的还是异步的?
我有一个应用程序可以打开一个新的意图。新的intent在datadabase上插入一些行,然后finish();然后返回到第一个屏幕,在该屏幕中,数据应该已使用新行刷新。我的代码在执行时不起作用,但在调试时起作用。。。所以可能在某个地方有些滞后。。。大概如何等待查询完成 这是我的密码: 在第一个屏幕上: 设置适配器和onResumeJava SQLiteDatabase是同步的还是异步的?,java,android,android-intent,android-sqlite,Java,Android,Android Intent,Android Sqlite,我有一个应用程序可以打开一个新的意图。新的intent在datadabase上插入一些行,然后finish();然后返回到第一个屏幕,在该屏幕中,数据应该已使用新行刷新。我的代码在执行时不起作用,但在调试时起作用。。。所以可能在某个地方有些滞后。。。大概如何等待查询完成 这是我的密码: 在第一个屏幕上: 设置适配器和onResume @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, B
@Override
public 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;
}
@Override
public 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;
}
公共列表getAllFilters(字符串类型){
List lstFilter=new ArrayList();
//hp=新HashMap();
SQLiteDatabase db=this.getReadableDatabase();
Cursor res=db.rawQuery(“从“+FILTERS\u TABLE\u NAME+”中选择*,其中type='“+type+'”,null);
res.moveToFirst();
while(res.isAfterLast()==false){
添加(新筛选器(res.getInt(res.getColumnIndex(FILTERS\u COLUMN\u ID)),
res.getString(res.getColumnIndex(FILTERS\u COLUMN\u NAME)),
res.getString(res.getColumnIndex(FILTERS\u COLUMN\u NUMBER)),
res.getString(res.getColumnIndex(FILTERS\u COLUMN\u PHOTO)),
res.getString(res.getColumnIndex(FILTERS\u COLUMN\u TYPE));
res.moveToNext();
}
res.close();
db.close();
回流过滤器;
}
有什么想法吗?既然要替换列表的内容,请调用
适配器.notifyDataSetChanged()
刷新整个列表。刷新列表后,调用notifyDataSetChanged()就足够了,不过,我通常只需重置适配器:
adapter = new ClaimListAdapter(this, thisContext, claimItems);
mClaimList.setAdapter(adapter);
“SQLiteDatabase是同步的还是异步的?”--一般来说,
SQLiteDatabase
上的方法是同步的。这是我以前使用过的。。。没有变化。