Resources$NotFoundException: Resource ID #0x0 in AlertDialog

后端 未结 3 1289
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 02:36

I have a RecyclerView, and in its adapter, I have created something similar to an OnLongClickListener, which I am calling an OnEntryLongClick

相关标签:
3条回答
  • 2020-12-31 03:05

    Pass your context correctly by casting it to Activity if you are calling from a Fragment.

    In Kotlin,

     AlertDialog.Builder(context as HomeActivity)
    
    0 讨论(0)
  • 2020-12-31 03:06

    Change getBaseContext() in the AlertDialog.Builder instantiation to the current Activity instance. For example:

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    

    An AlertDialog requires certain resources whose values are provided by the themes and styles attached to the Context it uses. The Context returned by getBaseContext() doesn't have those attached, but the Activity does. Indeed, whenever a Context is needed for a UI component - e.g., Dialogs, Views, Adapters, etc. - the current Activity is usually what you want to use.

    0 讨论(0)
  • 2020-12-31 03:07

    Try putting an style for your Dialog that extends Theme.AppCompat.Light.Dialog.Alert

    <style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert" />

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.MyDialogTheme);
    

    This works for me.

    Greetings

    0 讨论(0)
提交回复
热议问题