I want to list different values in a table. These values come from a database.
So a user creates a new article with these attributes: 'articlename', 'ariclegroup', 'and 'price'. The user should be able to create a picture optionally.
The values that have to displayed always: 'id', 'article name', 'articlegroup' and 'price'.
When the article is created with a picture, the picture should be displayed in the table.
All values and the picture is shown in the table, but the picture haven't got the correct position in table.
Here is the code to list alll elements:
private void zeilen_darstellen() {
// erhalte das TabellenLayout, um die einzelnen Texte der Zeilen dem TabellenLayot hinzuzufügen
TableLayout tableLayout_bestehende_artikel = (TableLayout) findViewById(R.id.bestehende_artikel_tablelayout);
// LayoutParameter, damit die Abstände der Zeilen korrekt sind
TableRow.LayoutParams layoutParams_tabellenLayout = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
int counter_zeilen_darstellen = 0;
Log.d("refactoring020", "refactoring020 " + globale_anzahl_artikelstandard);
// muss bei id = 1 beginnen, da id = 0 die Überschrift ist
// durchlaufe alle gespeicherten Elemente, um neue Zeilen dem Tabellenlayout hinzuzufügen
for ( int id = 1; id <= globale_anzahl_artikelstandard; id++) {
Log.d("table01", "table01 " + id + "|" + globale_anzahl_artikelstandard);
row = new TableRow(this);
// Abstände für die neu erstellten Zeilen
int linkerAbstand_zeilen = 10;
int obererAbstand_zeilen = 2;
int rechterAbstand_zeilen = 10;
layoutParams_tabellenLayout.setMargins(linkerAbstand_zeilen, obererAbstand_zeilen, rechterAbstand_zeilen, 0);
row.setLayoutParams(layoutParams_tabellenLayout);
ImageView bild_view = null;
try {
if (bilder != null) {
Bitmap bild = BitmapFactory.decodeFile(bilder[id - 1]);
bild_view = new ImageView(this);
bild_view.setMaxWidth(120);
bild_view.setMinimumWidth(120);
bild_view.setMinimumHeight(120);
bild_view.setMaxHeight(120);
bild_view.setImageBitmap(bild);
}
} catch (ArrayIndexOutOfBoundsException ar) {
Log.d("in bilder_exception", "in bilder_exception " + ar.getMessage());
}
TextView id_text = new TextView(this);
id_text.setLayoutParams(layoutParams_tabellenLayout);
Log.d("table06", "table06 " + id_datenbank);
TextView artikelname_text = new TextView(this);
artikelname_text.setLayoutParams(layoutParams_tabellenLayout);
TextView artikelgruppe_text = new TextView(this);
artikelgruppe_text.setLayoutParams(layoutParams_tabellenLayout);
TextView preis_text = new TextView(this);
preis_text.setLayoutParams(layoutParams_tabellenLayout);
TextView herstellernummer_text = new TextView(this);
herstellernummer_text.setLayoutParams(layoutParams_tabellenLayout);
TextView laenge_text = new TextView(this);
laenge_text.setLayoutParams(layoutParams_tabellenLayout);
TextView breite_text = new TextView(this);
breite_text.setLayoutParams(layoutParams_tabellenLayout);
TextView hoehe_text = new TextView(this);
hoehe_text.setLayoutParams(layoutParams_tabellenLayout);
TextView farbe_text = new TextView(this);
farbe_text.setLayoutParams(layoutParams_tabellenLayout);
TextView pfad_text = new TextView(this);
pfad_text.setLayoutParams(layoutParams_tabellenLayout);
try {
id_text.setText("" + id_array[counter_zeilen_darstellen]);
Log.d("id_test00", "id_test00 " + "count2: " + counter_zeilen_darstellen + "|" + id_text.getText().toString() + "|" + id_array[counter_zeilen_darstellen]);
artikelname_text.setText(artikelname_array[counter_zeilen_darstellen]);
artikelgruppe_text.setText(artikelgruppe_array[counter_zeilen_darstellen]);
preis_text.setText(preis_array[counter_zeilen_darstellen]);
} catch (IndexOutOfBoundsException ie) {
id_text.setText("" + id_array[counter_zeilen_darstellen-1]);
Log.d("id_test01", "id_test01 " + id_text.getText().toString() + "|" + id_array[counter_zeilen_darstellen-1]);
artikelname_text.setText(artikelname_array[counter_zeilen_darstellen-1]);
artikelgruppe_text.setText(artikelgruppe_array[counter_zeilen_darstellen-1]);
preis_text.setText(preis_array[counter_zeilen_darstellen-1]);
}
row.addView(id_text, layoutParams_tabellenLayout);
try {
// TODO: Bild wird an der falschen Position dargestellt
row.addView(bild_view, layoutParams_tabellenLayout);
} catch (NullPointerException np) {
TextView text = new TextView(globaler_Context);
text.setText("Kein Bild");
row.addView(text, layoutParams_tabellenLayout);
}
row.addView(artikelname_text, layoutParams_tabellenLayout);
row.addView(artikelgruppe_text, layoutParams_tabellenLayout);
row.addView(preis_text, layoutParams_tabellenLayout);
row.addView(herstellernummer_text, layoutParams_tabellenLayout);
row.addView(laenge_text, layoutParams_tabellenLayout);
row.addView(breite_text, layoutParams_tabellenLayout);
row.addView(hoehe_text, layoutParams_tabellenLayout);
row.addView(farbe_text, layoutParams_tabellenLayout);
row.addView(pfad_text, layoutParams_tabellenLayout);
tableLayout_bestehende_artikel.addView(row, id);
row.setOnClickListener(table_row_listener);
Log.d("table03", "table03 ");
counter_zeilen_darstellen++;
}
}
To understand what I mean some pictures:
no article is saved in the database (just the headline is shown):
First article (without picture) with articlename: "test01", articlegroup: "Standard" and price: 1
Second article (without picture ) with articlename: "test02", articlegroup: "Standard" and price: 2
Third article (first article with picture) with articlename: "test03", articlegroup: "Standard" and price: 3:
The picture should be at position '3' and the articlename and price is false.
Fourth article (second article with picture) with articlename: "test04", articlegroup: "Standard" and price: 4:
Thanks a lot for helping.
Aucun commentaire:
Enregistrer un commentaire