
我有一个RecyclerVIEw,在其适配器中,我创建了类似于OnLongClickListener的东西,我调用OnEntryLongClickListener以避免混淆.
我正在使用AlertDialog显示包含不同 *** 作的列表项的对话框.但是,我收到以下错误:
E/AndroIDRuntime: androID.content.res.Resources$NotFoundException: Resource ID #0x0 at androID.content.res.Resources.getValue(Resources.java:2345) at androID.content.res.Resources.loadXmlResourceParser(Resources.java:3910) at androID.content.res.Resources.getLayout(Resources.java:2161) at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:413) at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:366) at androID.support.v7.app.AlertController$AlertParams.createListVIEw(AlertController.java:734) at androID.support.v7.app.AlertController$AlertParams.apply(AlertController.java:711) at androID.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:883) at com.mycompany.myapp.ThisActivity.onEntryLongClick(ThisActivity.java:135) at com.mycompany.myapp.adapter.RVAdapter$RVVIEwHolder.onLongClick(RVAdapter.java:41) at androID.vIEw.VIEw.performlongClick(VIEw.java:5236) 以下是我使用的相关代码:
adapter.setonEntryLongClickListener(new RVAdapter.OnEntryLongClickListener() { @OverrIDe public voID onEntryLongClick(VIEw vIEw, int position) { final MinIEntry thisEntry = entryList.get(position); AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext()); builder.setTitle(thisEntry.getEntryname());); builder.setItems(R.array.quickactions, new DialogInterface.OnClickListener() { public voID onClick(DialogInterface dialog, int which) { // Other code here } }); AlertDialog alert = builder.create(); // The error log points to this line alert.show(); }});mRecyclerVIEw.setAdapter(adapter);以及我用于数组的XML:
<string-array name="quickactions"> <item>Add to Favourites</item> <item>More information</item></string-array>我不确定它是否重要,但我从androID.support.v7.app.AlertDialog(来自v7支持库)导入AlertDialog.
我怎么解决这个问题?
解决方法:
将AlertDialog.Builder实例化中的getBaseContext()更改为当前的Activity实例.例如:
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);AlertDialog需要某些资源,其值由附加到其使用的Context的主题和样式提供. getBaseContext()返回的Context没有附加的Context,但Activity有.实际上,每当UI组件需要Context时 – 例如,对话框,视图,适配器等 – 当前的Activity通常是您想要使用的.
总结以上是内存溢出为你收集整理的android – 资源$NotFoundException:AlertDialog中的资源ID#0x0全部内容,希望文章能够帮你解决android – 资源$NotFoundException:AlertDialog中的资源ID#0x0所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)