我有一个 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$2.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>
我不确定这是否重要,但我正在从v7支持库中导入android.support.v7.app.AlertDialog
中的AlertDialog
。
我该怎么解决这个问题?
AlertDialog.Builder
е®һдң‹еЊ–дёзљ„getBaseContext()
ж›өж”№дёғеҢ“е‰ҚActivityе®һдң‹гЂ‚дң‹е¦‚пәЊnew AlertDialog.Builder(ThisActivity.this)
гЂ‚ - Mike M.