ListView in Aktivity per Knopfdruck aktualisieren?

  • 1 Antworten
  • Letztes Antwortdatum
M

MikeRo

Neues Mitglied
0
Hallo Ich habe folgendes Problem, es ist bestimmt trivial, aber ich komme nicht auf die Lösung. (Ich bin noch Anfänger, was Android Entwicklung angeht)

Ich habe ein Layout, mit 3 Textfeldern und einem Button, wenn ich nun etwas in die Textfelder eingebe, wird nach druck des Buttons die Liste unter dem Button mit den Ergebnissen befüllt.

Zum Einstieg will ich erst mal nur die Liste befüllen, wenn der Knopf gedrückt wird.

Ich habe eine extra Klasse zum befüllen der Liste erstellt.

LokalFilterListeFuellen
Code:
...
public class LokalFilterListeFuellen extends ListActivity {

    private static String TAG = LokalFilterListeFuellen.class.getSimpleName();

    public void ListeBefuellen() {
        Log.v(TAG, "ListeBefüllen");
        ListView listView = (ListView) findViewById(R.id.LokalFilterListe);
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
          "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
          "Linux", "OS/2" };

        // First paramenter - Context
        // Second parameter - Layout for the row
        // Third parameter - ID of the TextView to which the data is written
        // Forth - the Array of data
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_1, android.R.id.text1, values);

        // Assign adapter to ListView
        listView.setAdapter(adapter); 
    }
...
Sie wird in der Activity LokalFilter aufgerufen

Code:
...
    public void onClick(View view) {
       if (view == button_lf_suchen) {
            LokalFilterListeFuellen ListeBefuellen = new LokalFilterListeFuellen();
            ListeBefuellen.ListeBefuellen();
        }
...
und hier noch das Layout layout_lokal_filter
Code:
<?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" >

    <EditText
        android:id="@+id/edit_lf_lokalname"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/edit_lf_lokalname" >
    </EditText>

    <EditText
        android:id="@+id/edit_lf_strasse"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/edit_lf_strasse" >
    </EditText>

    <EditText
        android:id="@+id/edit_lf_ort"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/edit_lf_ort" >
    </EditText>

    <Button
        android:id="@+id/button_lf_suchen"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/button_lf_suchen"
        android:textColor="@color/lila" />

    <TextView
        android:id="@+id/txt_lf_ub_vorhandene"
        style="@style/Ueberschriften2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/txt_lf_ub_vorhandene" />
    
    
    <ListView
        android:id="@+id/LokalFilterListe"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>
Es will aber nicht so recht klappen.
 
du hast eine activity

1) eine activity wird niemals per new xx instanziert.
2) kannst du beim knopfdruck ja einfach ListeBefüllen() aufrufen, müsste doch irgendwas machen
3) schau dir mal die java coding convetions an, dann ist es für andere einfacher deinen code zu lesen
 
Zurück
Oben Unten