質問

編集: 学んだレッスン:オリエンテーションやものを設定しない可能性があります。

に従って http://developer.android.com/guide/topics/ui/dialogs.html#customdialog カスタムアラートダイアログを作成しようとしています。具体的には、それぞれが2つのテキストビューを含む複数のビュー(helpitemviewと呼ばれる)を含むダイアログを作成しています。これを使用して、タイトルコンテンツペアの形でヘルプ情報を含むアラートダイアログを作成します。

私の問題は、最初のhelpItemviewのみが現れることですが、私はそれらの束を作成しています。アラートダイアログにこれを制限しているものはありますか?私は自分のコードを台無しにしましたが、私のアクティビティの主な線形レイアウトに添付されたときにすべてのhelpItemViewが表示されることに問題はありませんでした。この問題はアラートダイアログ内にのみ表示されるようです。

私のアクティビティ内のコード:

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で開発しています。それがうまく機能する(またはまったく)機能する場合、私はリストビューに変換することを受け入れていますが、誰かがそれを理解できるなら、現在のコードの何が悪いのか知りたいです。

役に立ちましたか?

解決

私はあなたが変えるべきだと思います helpGroup水平方向へのオリエンテーション。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top