0

I have a small custom dialog in wich I have a ListView with id:list. I want to populate it with strings I have in my resources (R.array.tones), but I have really big problems making this work, have tried many different solutions this is the latest which I think would work but it throws an null pointer exception on the toneList.

    Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.tone_dialog);
    dialog.setTitle(R.string.tonePromptTitle);
    ListView toneList = (ListView)findViewById(R.id.list);

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.tones, android.R.layout.simple_list_item_1);

    toneList.setAdapter(adapter);

    dialog.show();

My class is just extending Activity not ListActivity, and I would like to have it that way otherwise I must create a new class just for the listview. I apologize for the long code, I'm new here and hasn't really figured out all functionality yet.

4

2 回答 2

5

您应该在对话框中查找视图:

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

:)

于 2011-10-20T12:43:47.883 回答
0

您没有在对话框布局中搜索toneList. 请尝试以下操作:

ListView toneList = (ListView)dialog.findViewById(R.id.list);
于 2011-10-20T12:45:57.460 回答