Permanently adding an item to an existing alertdialog?

前端 未结 2 1287
死守一世寂寞
死守一世寂寞 2021-01-23 08:54

My goal is to permanently add an item to an existing AlertDialog.

The XML array for the AlertDialog is:


    

        
2条回答
  •  余生分开走
    2021-01-23 09:35

    You can leave the defaults in the xml file but you'll need to store the custom servers in a database. Then you can pull from both sources into a single array and put that in the dialog.

    final CharSequence[] items = {"Red", "Green", "Blue"};
    
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Pick a color");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
        }
    });
    AlertDialog alert = builder.create();
    

提交回复
热议问题