前提
ListViewの使い方がわからない方はこちらを参考にしていただきたい。
https://qiita.com/QiitaD/items/6123bb53d358c51beb97
参考URL
こちらを参考にした。この方の記事で紹介されているサンプルではうまくいった。
https://qiita.com/ueno-yuhei/items/ef6d835e143592e7a3f0
使い方(未完)
まずListViewを作り、それを以下のようにしてAlertDialogにセットした。
//ListView作成
listView.setAdapter(adapter);
//AlertDialogにセット
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("タイトル")
.setView(listView)
.setPositiveButton("OK", null)
.create();
dialog.show();
しかし
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
というエラーが発生した。
まだ解決できていないが、この方の記事が参考になりそうである。
http://www.sumahodays.sblo.jp/article/105586834.html
感想
ListViewをAlertDialogにセットするのみの簡単な実装だと思っていたが、うまくいかなかった。早く使えるようにしたい。