如何建立1按鈕,顯示複選餐點項目,結果顯示在editText上 注意:整個事件程式碼都必須放在 onCreate() { } 下面 .......................... 範例: import android.view.*; import android.widget.*; import android.app.AlertDialog; import android.content.DialogInterface; import android.app.Dialog; String[] items = {"項目一", "項目二", "項目三"}; boolean[] itemsChecked = new boolean[items.length]; protected Dialog onCreateDialog(int id) { switch (id) { case 0: // 傳回AlertDialog對話方塊 return new AlertDialog.Builder(this) .setTitle("輸出所要顯示的訊息文字?") .setPositiveButton("確定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { String msg = ""; for (int index = 0; index < items.length; index++) { if (itemsChecked[index]) msg += items[index] + "\n"; } TextView output = (TextView) findViewById(R.id.editText1); output.setText(msg); } }) .setNegativeButton("取消", null) .setMultiChoiceItems(items,itemsChecked, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { //Toast.makeText(this,items[which] + (isChecked ? " 勾選": "沒有勾選"),Toast.LENGTH_SHORT).show(); } }) .create(); } return null; } // button1事件處理程序 public void button1_Click(View view) { showDialog(0); // 顯示對話方塊 }