Auf Thema antworten

Wie kann ich in Android ein Buttonfeld erstellen, welches auch während des Programmlaufs geändert

werden kann (für Memoryspiel mit dynamischer Anzahl von Karten)?


MemoryActivity.java:

[code]

package com.memory;


import android.app.Activity;

import android.os.Bundle;

import android.widget.Button;


public class MemoryActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        Button b = new Button(this); //Button wird nicht angezeigt, warum nicht?

        setContentView(R.layout.main);

       

    }

}

[/code]


main.xml:

[code]

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

<TextView 

    android:layout_width="fill_parent"

    android:layout_height="wrap_content"

    android:text="@string/hello"

    />

</LinearLayout>

[/code]


Sehe ich das richtig, dass die Buttons nicht in die main.xml eingetragen werden,

da diese nur ein festes Layout geeignet ist und die Anzahl der Buttons sich

während des Programmlaufs ändert?



Oben