Ich habe einige Schwierigkeiten mit dieser Tabelle, die eine neue Zeile nach 5 Tasten erstellen sollte. Es stürzt auch ab, wenn ich button.setText (lesson.getId());Dynamisch 5 Tasten in 1 Zeile laden
LesSelectionActivity.java
public static final int LESSON_ROW_COUNT = 5;
public void setButtonLessons() {
//draw LesSelection
setContentView(R.layout.activity_drumles);
TableLayout layout = (TableLayout) findViewById(R.id.les_select_layout);
int buttonIdCounter = 0;
for (Lesson lesson : getArrayLesson()) {
int columnCounter = 0;
TableRow tr = new TableRow(this);
TableRow.LayoutParams params = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
params.setMargins(30, 0, 30, 0);
tr.setLayoutParams(params);
layout.addView(tr);
if (columnCounter % LESSON_ROW_COUNT == 0) {
tr = new TableRow(this);
params = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT);
params.setMargins(30, 0, 30, 0);
tr.setLayoutParams(params);
layout.addView(tr);
}
Button button = new Button(this);
button.setId(buttonIdCounter);
//button.setText(lesson.getId());
button.setOnClickListener(this);
button.setBackgroundResource(R.drawable.buttonsoranje);
TableRow.LayoutParams paramsRow = new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
paramsRow.column = columnCounter % LESSON_ROW_COUNT;
params.gravity = Gravity.CENTER_HORIZONTAL;
tr.addView(button);
buttonIdCounter++;
columnCounter = (columnCounter + 1) % LESSON_ROW_COUNT;
}
}
Also, warum setText funktioniert nicht aber setBackgroundResource tut? (Beachten Sie, dass ich "//" habe, weil es jetzt nicht funktioniert, der Awnser ist nicht "remove //")
Warum gibt es nur 1 Button pro Zeile?
Ich habe es behoben, die "für (Lektion Lektion: getArrayLesson()) {" wurde zu hoch eingestellt, legte es direkt über dem if, dann hat es funktioniert. – Jaxhead