How can inflate a layout containing listview in a alert dialog?

前端 未结 1 1393
陌清茗
陌清茗 2021-02-13 17:53

I am using a listview with a custom adapter in a layout. Now i am trying to bring that layout containing list to my alertdialog. I tried to bring simple layouts not containing l

1条回答
  •  日久生厌
    2021-02-13 18:22

    All you are doing is inflating a view into your alert dialog. You aren't setting the adapter on that listview so of course it's going to appear to not be working (since its empty).

    You need to do something like:

    View view = getLayoutInflater().inflate( R.layout.smill, null);
    ListView listView = (ListView) view.findViewById(R.id.listView);
    YourCustomAdapter adapter = new YourCustomAdapter(parameters...);
    listView.setAdapter(adapter);
    
    AlertDialog.Builder dialog = new AlertDialog.Builder( this );
    dialog.setView(view);
    ...
    ...
    ...
    dialog.show();  
    

    0 讨论(0)
提交回复
热议问题