“new ArrayAdapter<String>(this ” error when used in dialog null exception

懵懂的女人 提交于 2019-12-12 04:42:44

问题


hi, I have been working on a dialog box and i need a ListView inside the dialog box. The problem is i cant use "this" "new ArrayAdapter(this"

Can someone help me?

ListView dialog_ListView = (ListView)dialog.findViewById(R.id.list);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, comment11);

dialog_ListView.setAdapter(adapter);

回答1:


Maybe this workaround helps you:

ListView dialog_ListView = (ListView)dialog.findViewById(R.id.list);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(dialog_ListView.getContext(),android.R.layout.simple_list_item_1, comment11);

dialog_ListView.setAdapter(adapter);


来源:https://stackoverflow.com/questions/12554842/new-arrayadapterstringthis-error-when-used-in-dialog-null-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!