Android ListView wird nicht dargestellt

mlkike

Mitglied
Hallo liebes Forum,

ich habe ein Problem mit meiner ListView und meinem dazugehörigen Adapter.
Ich habe eine List mit x Objekten darin, die in meiner ListView dargestellt werden sollen.
Dafür habe ich einen Adapter, der von BaseAdapter erbt.

Das Problem ist nun aber, dass die Methode getView() davon nicht aufgerufen wird, weshalb mir keine Liste angezeigt wird.

Meine Vermutung liegt nun beim Context, allerdings sind mir da die Ideen ausgegangen.

Ich übergebe dem Adapter die Activity, in der die ListView angezeigt werden soll.
Sozusagen: context = this;

Der Constructor vom Adapter wird aufgerufen.
Vielleicht hat ja hier jemand die zündende Idee, die mir grade fehlt!

Code:
Java:
dailyReports = new ArrayList<>();
        arrayAdapter = new DailyReportsAdapter(this);

        listView = (ListView) findViewById(R.id.listViewDailyReports);
        listView.setClickable(true);

        loadReportsFromDB();
        listView.setAdapter(arrayAdapter);

Java:
private class DailyReportsAdapter extends BaseAdapter {
        private List<DailyReport> dailyReports = Collections.emptyList();
        private final Context context;

        public DailyReportsAdapter(Context context) {
            this.context = context;
        }

        public void updateDailyReports(List<DailyReport> dailyReports) {
            this.dailyReports = dailyReports;
            notifyDataSetChanged();
        }

        @Override
        public int getCount() {
            return dailyReports.size();
        }

        @Override
        public Object getItem(int position) {
            return dailyReports.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView rowTvDate;
            TextView rowTvActivity;

            if (convertView == null) {
                convertView = LayoutInflater.from(context).inflate(R.layout.row_item_layout_daily_report, parent, false);
                rowTvDate = (TextView) convertView.findViewById(R.id.rowTvDate);
                rowTvActivity = (TextView) convertView.findViewById(R.id.rowTvActivity);
                convertView.setTag(new ViewHolder(rowTvDate, rowTvActivity));
            } else {
                ViewHolder viewHolder = (ViewHolder) convertView.getTag();
                rowTvDate = viewHolder.getRowTvDate();
                rowTvActivity = viewHolder.getRowTvActivity();
            }

            DailyReport currentDailyReport = (DailyReport) getItem(position);

            if (rowTvDate != null) {
                rowTvDate.setText(currentDailyReport.getDate());
            }
            if (rowTvActivity != null) {
                rowTvActivity.setText(currentDailyReport.getActivity());
            }
            return convertView;
        }
    }
 

walex

Mitglied
Hallo,

wo gibst Du dem Adapter denn die Liste? Wenn der Adapter über den Konstruktor initialisiert wird, hat er erstmal eine leere Liste - kein Wunder, dass getView() nicht aufgerufen wird.
Fehlt wohl der Aufruf von updateDailyReport() mit Daten...

walex
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
K Null-Pointer-Exception in ListView - wird über Datenbank gefüllt Android & Cross-Platform Mobile Apps 1
T Android: ListView-Adapter: Adapter wird ständig aufgerufen Android & Cross-Platform Mobile Apps 2
J ListView Item individuell einfärben Android & Cross-Platform Mobile Apps 17
I Android ListView, Werte aktualisieren ohne die Liste komplett neu zu laden Android & Cross-Platform Mobile Apps 5
W ListView OnItemClicklistener setzen mit Ausgabe Android & Cross-Platform Mobile Apps 35
I Android ListView (Custom) soll auf Hardwaretasten nicht reagieren. Android & Cross-Platform Mobile Apps 10
W ListView und Arrays... Android & Cross-Platform Mobile Apps 68
W Android Wieso kann ich keine ListView mehr zum Layout hinzufügen? Android & Cross-Platform Mobile Apps 1
W Android Kann keine ListView mehr in der MainActivtiy anzeigen, obwohl noch sehr viel Platz frei ist Android & Cross-Platform Mobile Apps 1
L ListView aktuallisiert sich nicht Android & Cross-Platform Mobile Apps 15
N Probleme mit custom dynamic ListView Android & Cross-Platform Mobile Apps 15
L Android ListView kollabiert in Scrollview Android & Cross-Platform Mobile Apps 9
A ImageButton in ListView Item bei klick ändern Android & Cross-Platform Mobile Apps 3
J Android Suche in einer ListView Android & Cross-Platform Mobile Apps 3
H Android ArrayList <-> ArrayAdapter <-> ListView Android & Cross-Platform Mobile Apps 10
L Android ListView swipe zum löschen Android & Cross-Platform Mobile Apps 1
B Android ListView set custom check Image and delete Android & Cross-Platform Mobile Apps 0
Maresuke Android Android ListView Textfarbe und Texthintergrund ändern? Android & Cross-Platform Mobile Apps 5
A Android Problem mit ListView und OnItemClickListener.. Android & Cross-Platform Mobile Apps 10
S Listview Einträge aus "xml" Datei Android & Cross-Platform Mobile Apps 1
S Android Studio MySql Daten in Listview mit sub Item Android & Cross-Platform Mobile Apps 11
S Textdatei in ListView einlesen Tutorial gesucht!? Android & Cross-Platform Mobile Apps 3
kaoZ Tutorial .xml Layouting für z.B ListView elemente Android & Cross-Platform Mobile Apps 7
M Android ListView und Checkbox Android & Cross-Platform Mobile Apps 6
L TableRows in ListView darstellen Android & Cross-Platform Mobile Apps 2
M ListView mit ListAdapter füllen Android & Cross-Platform Mobile Apps 5
U Android ListView Frage Android & Cross-Platform Mobile Apps 6
L Android SearchBox für Custom Listview Android & Cross-Platform Mobile Apps 5
H Android ListView Images aus dem Internet via Thread Android & Cross-Platform Mobile Apps 3
H Android SAX|ListView NullPointerException Android & Cross-Platform Mobile Apps 2
A Probleme mit ListView / ArrayAdapter Android & Cross-Platform Mobile Apps 3
W Reward Ads AdMob wird nicht ausgeliefert. Android & Cross-Platform Mobile Apps 9
J Spinner wird nicht aktualisiert Android & Cross-Platform Mobile Apps 6
Naxon89 Duplicate class kotlin - und dies ohne das es angewendet wird Android & Cross-Platform Mobile Apps 1
ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 4
W Bildschirm Nutzung Überwachen der App Nutzer ink. was angeklickt wird Android & Cross-Platform Mobile Apps 35
N XY-Plottet keine Daten obwohl Funktion ausgeführt wird Android & Cross-Platform Mobile Apps 4
R Android Do not disturb: Sound wird nicht abgespielt Android & Cross-Platform Mobile Apps 2
O Google Admob Ad wird nicht geladen und App stürzt ab Android & Cross-Platform Mobile Apps 1
M Paper DB wird in Android Studio nicht erkannt Android & Cross-Platform Mobile Apps 7
R Audio wird nur 1 Mal abgespielt Android & Cross-Platform Mobile Apps 2
A GraphView => X- und Y-Achse wird nicht angezeigt Android & Cross-Platform Mobile Apps 5
A jpg wird im Android Studio nicht akzeptiert Android & Cross-Platform Mobile Apps 3
Arif Android Radiobutton wird nicht deaktiviert Android & Cross-Platform Mobile Apps 1
Arif Android Canvas wird nicht gezeichnet? Android & Cross-Platform Mobile Apps 0
J Notification wird nicht angezeigt wenn App nicht offen ist. Android & Cross-Platform Mobile Apps 6
M TypedArray-Resource wird falsch geladen Android & Cross-Platform Mobile Apps 7
W Preview wird nicht korrekt angezeigt Android & Cross-Platform Mobile Apps 0
B Profilpic wird nach anmeldung nicht angezeigt. Android & Cross-Platform Mobile Apps 2
K Methode wird nicht gefunden Android & Cross-Platform Mobile Apps 1
J Kamera - Foto wird nicht gespeichert Android & Cross-Platform Mobile Apps 2
V Android Wird mein Vorhaben funktionieren? (Apk Datei decompilieren, bearbeiten, compilieren) Android & Cross-Platform Mobile Apps 2
G App wird nach Installation auf Smartphone beendet Android & Cross-Platform Mobile Apps 1
L Dialog anzeigen wenn auf Button gedrückt wird. Android & Cross-Platform Mobile Apps 4
S Android neue Version des Programms wird nicht in Emulator geladen Android & Cross-Platform Mobile Apps 1
O Android Switch Widget wird nicht angezeigt Android & Cross-Platform Mobile Apps 1
N PriceScannerApp: warum wird nach dem Scannen Display gleich schwarz? Android & Cross-Platform Mobile Apps 4
P Herausfinden, welches Fragment gerade angezeigt wird. Android & Cross-Platform Mobile Apps 1
M Android Nur erste Zeile wird vom Server empfangen Android & Cross-Platform Mobile Apps 0
A App wird bei start des Timers beendet Android & Cross-Platform Mobile Apps 1
A Wieso wird die App beendet ??? Android & Cross-Platform Mobile Apps 2
B Alle Daten gehen verloren, wenn die Displaysperre aktiviert wird? Android & Cross-Platform Mobile Apps 21
P trotz invalidate() wird onDraw() nicht aufgerufen Android & Cross-Platform Mobile Apps 15
W XML Layout: wann wird geladen? Android & Cross-Platform Mobile Apps 10
K Android Temperaturconverter, R.id.element wird nicht gefunden Android & Cross-Platform Mobile Apps 20
A onDraw wird nicht aufgerufen Android & Cross-Platform Mobile Apps 14
A Android Dialog wird nicht sofort angezeigt Android & Cross-Platform Mobile Apps 12
W ImageView wird nicht angezeigt Android & Cross-Platform Mobile Apps 19
F Android Datenbank upgrade wird nicht durchgeführt Android & Cross-Platform Mobile Apps 2
F Android R.raw wird nicht gefunden Android & Cross-Platform Mobile Apps 5
P ID wird nicht erzeugt Android & Cross-Platform Mobile Apps 2
C Problem Device/Emulator wird nicht erkannt Android & Cross-Platform Mobile Apps 3
R Zeichen-Codierung in (SMS) TextMessage, "_" wird § Android & Cross-Platform Mobile Apps 2
W MoveEvent reagiert nicht Game Android & Cross-Platform Mobile Apps 1
W Cookie Manger übermittelt nicht Android & Cross-Platform Mobile Apps 1
M PythonInterpreter funktioniert nicht richtig NoClassDefFoundError Android & Cross-Platform Mobile Apps 1
I Android SharedPreferences wenn App auf externem Speicher klappt nicht Android & Cross-Platform Mobile Apps 0
W Frisch generiertes Projekt Value nicht findbar NavController Drawer Android & Cross-Platform Mobile Apps 12
W WebView Linkvertise lädt nicht richtig oder bleibt grau Android & Cross-Platform Mobile Apps 10
W AlertDialog Eigenschaften existiert nicht mehr. Android & Cross-Platform Mobile Apps 14
W Wieso gehen Log nicht im Service? Android & Cross-Platform Mobile Apps 20
CT9288 Zufällige Zahlengenerierung scheint nicht richtig zu funktionieren Android & Cross-Platform Mobile Apps 5
M App crasht und ich bekomme es nicht behoben.:( Android & Cross-Platform Mobile Apps 17
K Android Android In-App-Purchase lädt nicht Android & Cross-Platform Mobile Apps 0
Besset Android http request an interne ip adresse funktioniert nicht Android & Cross-Platform Mobile Apps 8
R Android Visualizer engine kann nicht initialisiert werden Android & Cross-Platform Mobile Apps 3
OSchriever Navigation drawer Strings ändern sich nicht Android & Cross-Platform Mobile Apps 0
W Code läuft unter SDK 27 aber nicht SDK 30 Android & Cross-Platform Mobile Apps 17
N Android Ich kann mit meiner App nicht auf die Datenbank zugreifen Android & Cross-Platform Mobile Apps 4
ruutaiokwu Android Selbst entwickelter SMTP-Client läuft auf PC, nicht aber auf Android Android & Cross-Platform Mobile Apps 9
W Android Wieso geht getApplicationContext() bei Toast, aber nicht bei AlertDialog.Builder? Android & Cross-Platform Mobile Apps 36
A Android Studio: while-Schleife beginnt nicht Android & Cross-Platform Mobile Apps 5
T Android SDK-Manager startet nicht in Eclipse Android & Cross-Platform Mobile Apps 5
J Download und speichern mit jsch klappt nicht Android & Cross-Platform Mobile Apps 5
J Service starte nicht mehr Android & Cross-Platform Mobile Apps 13
J Firebase und Emulator startet nicht Android & Cross-Platform Mobile Apps 2
J ArrayAdapter zeigt Liste nicht an Android & Cross-Platform Mobile Apps 0
L Android Animationen werden nicht angezeigt Android & Cross-Platform Mobile Apps 0
Excess Android Service läuft nicht in Sandby weiter Android & Cross-Platform Mobile Apps 2
J App funktioniert auf Android 5, auf 6 nicht Android & Cross-Platform Mobile Apps 2

Ähnliche Java Themen

Neue Themen


Oben