Ich habe eine ListView, die gerade ausgefüllt wird. Ich habe den Inhalt der Datenquelle überprüft und enthält gültige Daten. Leider ist die Anzahl der Zeilen korrekt, aber der Text, den ich anzeigen möchte, wird nicht angezeigt.Text erscheint nicht in meiner ListView
Hier ist, wie ich die Listview bin Einrichtung:
private void setupUI() {
setContentView(R.layout.streamactivity);
this.streamListView = (ListView) findViewById(R.id.streamListView);
this.streamAdapter = new StreamAdapter(this, R.layout.streamactivityrow, messages);
streamListView.setAdapter(this.streamAdapter);
}
Hier ist mein Adapter:
private class StreamAdapter extends ArrayAdapter<STMessage> {
private ArrayList<STMessage> messages;
public StreamAdapter(Context context, int textViewResourceId, ArrayList<STMessage> messages) {
super(context, textViewResourceId, messages);
this.messages = messages;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.streamactivityrow, null);
}
STMessage aMessage = messages.get(position);
if (aMessage != null) {
TextView titleText = (TextView) v.findViewById(R.id.toptext);
TextView descriptionText = (TextView) v.findViewById(R.id.bottomtext);
if (titleText != null) {
titleText.setText(aMessage.getBody());
}
if (descriptionText != null) {
descriptionText.setText(aMessage.getFor_user_login());
}
}
return v;
}
}
Hier ist die XML für jede Zeile in der Liste:
<?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="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical" android:layout_height="0dip" android:singleLine="true" android:textSize="15sp" android:textStyle="bold" android:ellipsize="end" android:shadowColor="#000000" android:shadowDy="1.0" android:shadowRadius="1.0" android:textColor="#FFFFFF"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15sp" android:shadowColor="#000000" android:shadowDy="1.0" android:shadowRadius="1.0" android:textColor="#FFFFFF"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/dateText" android:shadowColor="#000000" android:shadowDy="1.0" android:shadowRadius="1.0" android:textColor="#E2E2E2"></TextView></LinearLayout>
</LinearLayout>
Hier ist das XML für die StreamActivity mit dem ListView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/streamListView"></ListView>
</LinearLayout>
Versuchen Sie eine Protokollierung (z. B. Log.d ("tag", ...)) in Ihrem getView-Code. Stellen Sie sicher, dass a) Ihre Ansichten korrekt gefunden werden und b) aMessage.getFor_user_login() gibt tatsächlich zurück, was Sie denken. Sie haben auch eine Menge Null-Checks, die Maskierungsfehler sein können - gibt es jemals einen gültigen Grund dafür, dass aMessage, titleText oder descriptionText in getView null sind? Wenn Sie diese bestimmten Null-Checks entfernen, was passiert dann? –