Hallo,
Ich habe eine frage zu dem Table Layout. Im Internet gibt es zu diesem
Thema nur wenige schlechte Tutorials. (Wenn ihr eins kennt, her damit)
Wenn ich den Code unten ausführe und den App starte dann bleibt der Bildschirm einfach schwarz.
Hat jemand Erfahrung mit Table Layout und kann mit Helfen ? Was muss die TableLayoutActivity
Activity für ein extends haben.
Hier der Code:
TableLayoutActivity :
public class TableLayoutActivity extends Activity {
int PROVINCE_Alberta = 0;
int PROVINCE_BC = 1;
int PROVINCE_Manitoba = 2;
int PROVINCE_NewBrunswick = 3;
int PROVINCE_Newfoundland = 4;
int PROVINCE_Northwest = 5;
int PROVINCE_NovaScotia = 6;
int PROVINCE_Nunavut = 7;
int PROVINCE_Ontario = 8;
int PROVINCE_PEI = 9;
int PROVINCE_Quebec = 10;
int PROVINCE_Saskatchewan = 11;
int PROVINCE_Yukon = 12;
int numProvinces = 13;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
String[] provinces = new String[numProvinces];
provinces[PROVINCE_Alberta] = "Alberta";
provinces[PROVINCE_BC] = "British Columbia";
provinces[PROVINCE_Manitoba] = "Manitoba";
provinces[PROVINCE_NewBrunswick] = "New Brunswick";
provinces[PROVINCE_Newfoundland] = "Newfoundland and Labrador";
provinces[PROVINCE_Northwest] = "Northwest Territories";
provinces[PROVINCE_NovaScotia] = "Nova Scotia";
provinces[PROVINCE_Nunavut] = "Nunavut";
provinces[PROVINCE_Ontario] = "Ontario";
provinces[PROVINCE_PEI] = "Prince Edward Island";
provinces[PROVINCE_Quebec] = "Quebec";
provinces[PROVINCE_Saskatchewan] = "Saskatchewan";
provinces[PROVINCE_Yukon] = "Yukon";
// Get the TableLayout
TableLayout tl = (TableLayout) findViewById(R.id.maintable);
Log.d("Main", "num:" + numProvinces);
// Go through each item in the array
for (int current = 0; current < numProvinces; current++)
{
Log.d("For", "Schleife" + current);
// Create a TableRow and give it an ID
TableRow tr = new TableRow(this);
tr.setId(100+current);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
// Create a TextView to house the name of the province
TextView labelTV = new TextView(this);
labelTV.setId(200+current);
labelTV.setText("hallo");
labelTV.setTextColor(Color.BLACK);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
// Create a TextView to house the value of the after-tax income
TextView valueTV = new TextView(this);
valueTV.setId(current);
valueTV.setText("$0");
valueTV.setTextColor(Color.BLACK);
valueTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(valueTV);
// Add the TableRow to the TableLayout
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
}
Main.xml:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="2"
android:id="@+id/maintable" >