相关疑难解决方法(0)

在片段中使用上下文

如何在片段中获取上下文?

我需要用我的数据库其构造函数采用的背景下,但getApplicationContext()FragmentClass.this没有工作,所以我能做些什么?

数据库构造函数

public Database(Context ctx)
{
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}
Run Code Online (Sandbox Code Playgroud)

java android android-context android-fragments

645
推荐指数
12
解决办法
46万
查看次数

recyclerview没有连接适配器; 跳过布局

刚刚在我的代码中实现了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附加了一个适配器.那为什么我一直收到这个错误?

我已经阅读了与同一问题相关的其他问题但没有帮助.

android recycler-adapter android-recyclerview

213
推荐指数
9
解决办法
28万
查看次数