我必须在运行时构建一个自定义对话框。根据具体情况,对话框应显示一到四个搜索栏。我想获得类似的东西:
- 标题1 搜索栏1
- 标题2 搜索栏2 ...
我正在试验取自 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 );
但是,它不是在两个不同的行中显示文本“滑动我”和搜索栏,而是仅显示文本。如何创建这样的自定义对话框?