修改:获得的经验:设置方向或内容可能不会显示。
根据http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog我正在尝试创建自定义提醒对话框。具体来说,我正在创建一个包含多个视图(称为HelpItemView)的对话框,每个视图都包含两个textview。我正在使用它来创建一个警告对话框,其中包含标题 - 内容对形式的帮助信息。
我的问题是只有第一个HelpItemView出现,虽然我正在创建它们。警报对话框中是否有限制此内容的内容?我把我的代码搞砸了,并且当它们被附加到我的活动的主要线性布局时显示所有HelpItemViews没有任何问题,似乎这个问题只出现在警报对话框中。
我的活动中的代码:
private void createHelp() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
Resources res = getResources();
LinearLayout help_root = (LinearLayout)getLayoutInflater().inflate(R.layout.help_frame, null);
LinearLayout help = (LinearLayout) help_root.findViewById(R.id.helpGroup);
help.addView(new HelpItemView(this, res.getString(R.string.help_main_welcome),
res.getString(R.string.help_main_welcome_content)));
help.addView(new HelpItemView(this, res.getString(R.string.add_id),
res.getString(R.string.help_add_id_content)));
help.addView(new HelpItemView(this, res.getString(R.string.view_ids),
res.getString(R.string.help_view_ids_content)));
help.addView(new HelpItemView(this, res.getString(R.string.view_map),
res.getString(R.string.help_view_map_content)));
help.addView(new HelpItemView(this, res.getString(R.string.browse_plants),
res.getString(R.string.help_browse_plants_content)));
help.addView(new HelpItemView(this, res.getString(R.string.btnQuickIdentification),
res.getString(R.string.help_btnQuickIdentification_content)));
help.addView(new HelpItemView(this, res.getString(R.string.btnOptions),
res.getString(R.string.help_options_content)));
builder.setView(help_root);
AlertDialog alert = builder.create();
alert.show();
}
helpframe.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ScrollView android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/helpGroup"></LinearLayout>
</ScrollView>
</LinearLayout>
HelpItemView.java
public class HelpItemView extends RelativeLayout {
private TextView m_vwItemTitle;
private TextView m_vwItemText;
public HelpItemView (Context context, String header, String content) {
super(context);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.help_item, this, true);
m_vwItemTitle = (TextView) this.findViewById(R.id.helpItemHeader);
m_vwItemText = (TextView) this.findViewById(R.id.helpItemText);
setContent(header, content);
}
private void setContent(String header, String content) {
m_vwItemTitle.setText(header);
m_vwItemText.setText(content);
}
}
help_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/helpItemHeader"
android:textSize="20sp"
android:textStyle="bold"
android:layout_gravity="center"
></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/helpItemText"
/>
</LinearLayout>
也许它的东西是愚蠢的,我只是想念它,我不知道。任何想法/帮助将非常感激。哦,我正在开发Android 1.6,如果这有任何区别。我愿意转换为列表视图,如果这样可以更好(或者根本),但我仍然想知道当前代码有什么问题,如果有人能弄明白的话。
答案 0 :(得分:3)
我认为你应该将helpGroup
的方向改为横向。