1
0

More than 3 years have passed since last update.

[Android] AlertDialogにListViewを表示する(未完)

Posted at

前提

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にセットするのみの簡単な実装だと思っていたが、うまくいかなかった。早く使えるようにしたい。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0