gpt4 book ai didi

android - 多个 View 未显示在自定义警报对话框中

转载 作者:太空狗 更新时间:2023-10-29 12:56:44 25 4
gpt4 key购买 nike

编辑:经验教训:设置方向或内容可能不会显示。

根据 http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog我正在尝试创建自定义警报对话框。具体来说,我正在创建一个包含多个 View (称为 HelpItemView)的对话框,每个 View 包含两个 TextView 。我正在使用它来创建一个警报对话框,其中包含标题-内容对形式的帮助信息。

我的问题是只有第一个 HelpItemView 出现,尽管我正在创建其中的一堆。警报对话框中是否有限制此操作的内容?我搞砸了我的代码,当所有的 HelpItemViews 附加到我的 Activity 的主要线性布局时,所有的 HelpItemViews 都没有出现任何问题,似乎这个问题只出现在警报对话框中。

我的 Activity 中的代码:

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();
}

帮助框架.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。如果转换为 ListView 效果更好(或完全没有),我愿意转换为 ListView ,但我仍然想知道当前代码有什么问题,如果有人能弄清楚的话。

最佳答案

我认为您应该将helpGroup 的方向更改为水平方向。

关于android - 多个 View 未显示在自定义警报对话框中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5865471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com