How to make BaseAdapter show AlertDialog android Application

后端 未结 4 1247
旧时难觅i
旧时难觅i 2021-01-22 11:09

How can I make the button in BaseAdapter in listView shows alertDialog, I tried that but it Stopped work unexpected (RunTime Error) my code is shown below .

any suggesti

4条回答
  •  醉酒成梦
    2021-01-22 11:18

    First thing your alertDialog is not even initialised.. so NPE .. and when you create it inside an Adapter make sure to use activity context and not ApplciatioContext

    AlertDialog alertDialog = new AlertDialog.Builder(YourACtivity.this);
    

    the above line should not be in the class level.. it should be inside getView() method... and use your activity instance as Context.. something like nameOfYourActivity.this

提交回复
热议问题