如何在片段中获取上下文?
我需要用我的数据库其构造函数采用的背景下,但getApplicationContext()并FragmentClass.this没有工作,所以我能做些什么?
数据库构造函数
public Database(Context ctx)
{
this.context = ctx;
DBHelper = new DatabaseHelper(context);
}
Run Code Online (Sandbox Code Playgroud) 刚刚在我的代码中实现了Recyclerview,取代了Listview.
一切正常.显示对象.
但是logcat说
15:25:53.476 E/RecyclerView:没有连接适配器; 跳过布局
15:25:53.655 E/RecyclerView:没有连接适配器; 跳过布局
代码
ArtistArrayAdapter adapter = new ArtistArrayAdapter(this, artists);
recyclerView = (RecyclerView) findViewById(R.id.cardList);
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
Run Code Online (Sandbox Code Playgroud)
如您所见,我已经为Recycleview附加了一个适配器.那为什么我一直收到这个错误?
我已经阅读了与同一问题相关的其他问题但没有帮助.