Get context inside onClick(DialogInterface v, int buttonId)?

前端 未结 4 1341
悲哀的现实
悲哀的现实 2020-11-29 03:36

Getting the context inside onClick(View view), the callback for a button\'s onClickListener(), is easy:

view.getContext()
         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 04:01

    inside setOnClickListener

    decelare this below the class

    Context context = this;

    and use this context

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);

提交回复
热议问题