Frage

Bearbeiten: Lektion gelernt: Stellen Sie die Orientierung oder das Zeug möglicherweise nicht auf.

Wie per http://developer.android.com/guide/topics/ui/dialogs.html#customdialog Ich versuche, einen benutzerdefinierten Alarmdialog zu erstellen. Insbesondere erstelle ich ein Dialogfeld, das mehrere Ansichten (als HelpitemView bezeichnet) enthält, die jeweils zwei Textviews enthalten. Ich verwende dies, um ein Warndialog zu erstellen, das Hilfeinformationen in Form von Titeltit-In-Intensiva-Paaren enthält.

Mein Problem ist, dass nur die erste HelpitemView auftaucht, obwohl ich ein paar davon erstelle. Gibt es etwas im Alarmdialog, das dies einschränkt? Ich habe mit meinem Code herumgemacht und hatte kein Problem damit, dass alle HelpitemViews angezeigt wurden, wenn sie an das lineare Layout meiner Aktivität angehängt wurden. Es scheint, dass dieses Problem nur im Alarmdialog angezeigt wird.

Code in meiner Aktivität:

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>

Vielleicht ist es etwas Dummes und ich vermisse es nur, ich weiß es nicht. Alle Gedanken/ Hilfe wären am meisten geschätzt. Oh, ich entwickle mich auf Android 1.6, wenn das einen Unterschied macht. Ich bin offen für die Konvertierung in eine ListView, wenn das besser funktionieren würde (oder überhaupt), aber ich würde immer noch gerne wissen, was mit dem aktuellen Code los ist, wenn jemand es herausfinden kann.

War es hilfreich?

Lösung

Ich denke, Sie sollten sich ändern helpGroupDie Ausrichtung nach horizontal.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top