“new ArrayAdapter(this ” error when used i

2019-08-19 01:26发布

问题:

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);