我必须在运行时构建自定义对话框。根据情况,对话框应显示一到四个查找条。我想获得这样的:与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);
但不是在两个不同行显示文本“滑我”和搜索栏,只显示文本。我如何创建这样的自定义对话框?