Custom ListView in a dialog

前端 未结 2 2064
小鲜肉
小鲜肉 2021-01-20 17:43

i have a list view , inside this list when click on an item of it ,it will show a custom list inside a dialog box

the dialog shows up but its only shows the title

2条回答
  •  旧巷少年郎
    2021-01-20 18:26

    You need to use AlertDialog.Builder -

    Refer this- Docs

    Edit -

    new AlertDialog.Builder(MyActivity.this)
                        .setAdapter(yourListAdapter, new DialogInterface.OnClickListener() {
    
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                             //TODO - Code when list item is clicked (int which - is param that gives you the index of clicked item)
                            }
                        })
                        .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
    
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
    
                            }
                        })
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        })
                        .setTitle("Dialog Title")
                        .setCancelable(false)
                        .show();
    

提交回复
热议问题