0
我想動態添加可變數量的按鈕到對話框。所以,因爲按鈕的數量沒有解決,我不能將它們添加到佈局文件。動態添加按鈕到對話框
這是我試了一下:
private void oeffne_dialog (String[] prediction_array) {
//GestureAnyWhere gestureAnyWhere = null;
// Activity activity = gestureAnyWhere.get_activity();
// TODO: bessere Lösung finden, als das Flag setzen zu müssen. Falscher Context
Dialog dialog = new Dialog (getApplicationContext());
dialog.getWindow().setType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
Log.d ("dialog", "dialog " + dialog + "|" + HintergrundService.this /*+ "|" + activity*/);
dialog.setContentView (R.layout.multiple_predictions_layout);
dialog.setTitle ("Bitte die zu startende Anwendung auswählen");
// Button button_id = (Button)dialog.findViewById (R.id.button_ID);
Button button;
for (int i = 0 ; i < prediction_array.length ; i++) {
/*
button_id = new Button (getApplicationContext());
button_id.setText (prediction_array [i]);
*/
Log.d ("aufrufe", "aufrufe " + i + prediction_array[ i ]);
button = new Button (getApplicationContext());
button.setText (prediction_array[ i ]);
button.setId (i);
}
dialog.show();
}
但有了這個代碼沒有按鈕將出現在對話框中。
感謝您的幫助。
你忘了'的addChild(按鈕)'來根視圖 – Robust