Android AlertDialog ————單選對話方塊
阿新 • • 發佈:2018-12-14
//彈出一個單選對話方塊 private void showSingleDialog() { //[1]構造對話方塊的例項 AlertDialog.Builder builder = new Builder(this); builder.setTitle("請選擇你喜歡的課程"); //[1.1]★★★★★★ final String items[] = {"android","ios","c++","html","遊戲"}; builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //[1]獲取選擇條目 String item = items[which]; //[2]把選擇的條目展示到toast上 Toast.makeText(getApplicationContext(), item, 1).show(); //[3]關閉對話方塊 dialog.dismiss(); } }); //[3]展示對話方塊 和toast一樣 一定要記得show出來 builder.show(); }
簡單的東西Copy過去用就好了