我必須在運行時構建自定義對話框。根據情況,對話框應顯示一到四個查找條。我想獲得這樣的:與Android的自定義對話框
- TITLE1 seekbar1
- 標題2 seekbar2 ...
我是從Android的開發者指南網頁所採取的FireMissilesDialogFragment示例代碼進行實驗。我已經修改了onCreateDialog()方法中添加以下代碼:
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Context context = builder.getContext();//getActivity().getBaseContext();
LinearLayout layout = new LinearLayout(context);
layout.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
SeekBar seek_bar = new SeekBar(context);
TextView text = new TextView(context);
text.setClickable(false);
text.setText("slide me");
layout.addView(text, new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
layout.addView(seek_bar, new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
builder.setView(layout);
但不是在兩個不同行顯示文本「滑我」和搜索欄,只顯示文本。我如何創建這樣的自定義對話框?