| |||||||
Das Thema "ListView zeigt nix an" befindet sich unter Android App Entwicklung auf Android-Hilfe.de.
|
| | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| freier Samsungsupporter Registriert seit: 05.08.2009
Beiträge: 119
Abgegebene Danke: 18
Erhielt 9 Danke für 7 Beiträge
| ich habe ein wenig Probleme mit der ListView. Nach einigem Lesen in der Doku bin ich zu folgendem Code gekommen: ResultViewer.java Code: public class ResultViewer extends ListActivity {
private static final String LONG_DATE_FORMAT = "dd MMM yyyy hh:mm";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
String pkgNo = this.getIntent().getStringExtra("package_id");
putResult(pkgNo);
}
private void putResult(String pkgnr) {
// getting the result from dummy data
History res = XMLParser.parse(null);
if (res == null) {
Toast.makeText(getBaseContext(), "Es konnte kein Ergebnis abgerufen werden.", Toast.LENGTH_LONG).show();
} else {
// matching the result to the UI
List<Map<String, String>> content = new ArrayList<Map<String, String>>();
for (Event event : res.getEvents()) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("date", event.getDisplayDate());
map.put("status", event.getDisplayStatus());
content.add(map);
}
// Create an array to specify the fields we want to display in the list
// (only TITLE)
String[] from = new String[] { "date", "status" };
// and an array of the fields we want to bind those fields to (in this
// case just text1)
int[] to = new int[] { R.id.result_item_date, R.id.result_item_status };
SimpleAdapter adapter = new SimpleAdapter(this, content, R.layout.result_list_item, from, to);
setListAdapter(adapter);
}
}
} Code: <?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">
<TextView android:id="@+id/lbl_result_title" style="@style/Caption"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="@string/lbl_result_title" android:layout_marginLeft="10px"
android:layout_marginTop="0px" />
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView android:id="@+id/lbl_tracking_id" style="@style/Label"
android:layout_column="1" android:text="@string/lbl_tracking_id"
android:layout_marginLeft="2px" android:layout_marginTop="2px" />
<TextView android:id="@+id/tracking_id" android:gravity="right"
android:text="@string/result_status_text_default"
android:layout_marginRight="2px" android:layout_marginTop="2px" />
</TableRow>
<TableRow>
<TextView android:id="@+id/lbl_result_date" style="@style/Label"
android:layout_column="1" android:text="@string/lbl_result_date"
android:layout_marginLeft="2px" android:layout_marginTop="2px" />
<TextView android:id="@+id/result_date" android:gravity="right"
android:text="@string/result_date_default"
android:layout_marginRight="2px" android:layout_marginTop="2px" />
</TableRow>
</TableLayout>
<ListView android:id="@+id/list"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_marginTop="0px"
android:scrollbars="vertical">
</ListView>
</LinearLayout> Code: 09-07 09:33:26.877: WARN/dalvikvm(1477): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
09-07 09:33:26.877: ERROR/AndroidRuntime(1477): Uncaught handler: thread main exiting due to uncaught exception
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.keineantwort.android.packagetracer/de.keineantwort.android.packagetracer.ResultViewer}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.os.Handler.dispatchMessage(Handler.java:99)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.os.Looper.loop(Looper.java:123)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ActivityThread.main(ActivityThread.java:3948)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at java.lang.reflect.Method.invokeNative(Native Method)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at java.lang.reflect.Method.invoke(Method.java:521)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at dalvik.system.NativeStart.main(Native Method)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ListActivity.onContentChanged(ListActivity.java:236)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:312)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.Activity.setContentView(Activity.java:1626)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at de.keineantwort.android.packagetracer.ResultViewer.onCreate(ResultViewer.java:27)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
09-07 09:33:26.897: ERROR/AndroidRuntime(1477): ... 11 more Hat einer ne Idee, was ich falsch mache? SirMArtin
__________________ follow me || Mod im SAMSUNG mob!le Forum Apps: Ist mein Zug pünktlich? | Fläschchenmixer Geräte: Galaxy S & Galaxy & Spica |
| | |
| | #2 (permalink) |
| Android-Hilfe.de Mitglied Registriert seit: 03.02.2009
Beiträge: 151
Abgegebene Danke: 11
Erhielt 11 Danke für 4 Beiträge
|
Im Layout Ordner muss in der XML Datei, welche das layout beschreibt die ListView folgendermaßen heissen: "@+id/android:list" (Siehe Fehlerbeschreibung 3 Zeile) z.B. <ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_y="35px" android:layout_height="330px"></ListView> |
| | |
| | #3 (permalink) |
| freier Samsungsupporter Registriert seit: 05.08.2009
Beiträge: 119
Abgegebene Danke: 18
Erhielt 9 Danke für 7 Beiträge
|
Hm, das hab ich aus der Fehlermeldung nicht gelesen. Ich hätte eher das android:id="" vermutet. ![]() Danke für den Hinweis! Jetzt ist die Exception weg, aber es wird immer noch nix angezeigt. Das Debugging zeigt mir, dass "content" gefüllt ist, wenn es in den Constructor des SimpleAdapter gesetzt wird. SirMArtin, etwas verzweifelnd
__________________ follow me || Mod im SAMSUNG mob!le Forum Apps: Ist mein Zug pünktlich? | Fläschchenmixer Geräte: Galaxy S & Galaxy & Spica Geändert von SirMArtin (08.09.2009 um 15:34 Uhr) |
| | |
| | #4 (permalink) |
| Fortgeschrittenes Mitglied Modell: HTC Desire Registriert seit: 08.04.2009
Beiträge: 441
Abgegebene Danke: 10
Erhielt 69 Danke für 49 Beiträge
|
Hi. Versuch mal bitte dem ListView in der XML eine "normale" eigene ID zu geben und dann im Quellcode mit findViewById("id") eine Referenz auf deinen Listview zu bekommen (die entspr. Variable muss natürlich vom Typ ListView sein) und dann diesem ListView mit setAdapter deinen SimpleAdapter zuweisen. Ich bin mir nicht sicher ob eine Activity, die von ListActivity erbt im Layout noch diverse andere Layout-Elemente haben kann/darf. Gruß, Shini |
| | |
| | #5 (permalink) |
| Android-Hilfe.de Mitglied Registriert seit: 03.02.2009
Beiträge: 151
Abgegebene Danke: 11
Erhielt 11 Danke für 4 Beiträge
|
Hmm ich weiss nur ich hatte das auch mit der ID. Kann die mal code von mir zeigen: Das ganze ist eine Highscoreliste hs.xml: Code: <AbsoluteLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:screenOrientation = "portrait" xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:text="OK" android:layout_height="50px" android:layout_width="200px" android:layout_x="55px" android:layout_y="380px" android:id="@+id/HSButton"></Button> <ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_y="35px" android:layout_height="330px"></ListView> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="HIGHSCORE" android:textSize="20px" android:layout_x="100px" android:layout_y="5px" android:textColor="#ffff00"></TextView> </AbsoluteLayout> Code: package com.android.blackjack;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;
public class HsActivity extends ListActivity implements OnClickListener
{
private BjDbAdapter database;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setContentView(R.layout.hs);
this.setRequestedOrientation(1);
database = new BjDbAdapter(this);
database.open();
fillHighscore();
database.close();
Button b = (Button)this.findViewById(R.id.HSButton);
b.setOnClickListener(this);
}
private void fillHighscore()
{
Cursor notesCursor = database.getHighscore();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{BjDbAdapter.KEY_NAME, BjDbAdapter.KEY_POINTS};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.text1, R.id.text2};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.hs_row, notesCursor, from, to);
setListAdapter(notes);
}
public void onClick(View v)
{
finish();
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
return super.onKeyDown(KeyEvent.KEYCODE_ENTER, event);
return super.onKeyDown(keyCode, event);
}
} |
| | |
| | #6 (permalink) |
| freier Samsungsupporter Registriert seit: 05.08.2009
Beiträge: 119
Abgegebene Danke: 18
Erhielt 9 Danke für 7 Beiträge
|
Jetzt lade ich die ListView "result_list" vorher und setze den Adapter daran. Tut ebenso wenig. Spannend ist, dass einfach nix passiert. Keine Fehler meldung, kein nix. Code: ListView listview = (ListView) findViewById(R.id.result_list);
SimpleAdapter adapter = new SimpleAdapter(this, content, R.layout.result_list_item, from, to);
listview.setAdapter(adapter); SirMArtin
__________________ follow me || Mod im SAMSUNG mob!le Forum Apps: Ist mein Zug pünktlich? | Fläschchenmixer Geräte: Galaxy S & Galaxy & Spica |
| | |
| | #9 (permalink) | ||
| freier Samsungsupporter Registriert seit: 05.08.2009
Beiträge: 119
Abgegebene Danke: 18
Erhielt 9 Danke für 7 Beiträge
| Zitat:
Im Originalpost ist der gesamte Code. Was fehlt Dir? Der Debugger zeigt, dass die Liste in jedem Fall gefüllt ist. Das "setAdapter" habe ich nicht gedebuggt. EDIT: Zitat: SirMArtin
__________________ follow me || Mod im SAMSUNG mob!le Forum Apps: Ist mein Zug pünktlich? | Fläschchenmixer Geräte: Galaxy S & Galaxy & Spica Geändert von SirMArtin (09.09.2009 um 11:19 Uhr) | ||
| | |
| | #10 (permalink) |
| Fortgeschrittenes Mitglied Modell: HTC Desire Registriert seit: 08.04.2009
Beiträge: 441
Abgegebene Danke: 10
Erhielt 69 Danke für 49 Beiträge
|
Ein Versuch noch: Dein TableLayout hat als "Höhe" fill_parent. Vllt bleibt dadurch schlicht kein Platz um den ListView anzuzeigen??! Gruß, Shini |
| | |
| Folgender Benutzer bedankt sich bei Shinigami für diesen Beitrag: | SirMArtin (09.09.2009) |
![]() |
|
| Themen-Optionen | |
| Ansicht | |
| |
| ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| micro SD Karte tut nix | creepin | Zubehör für Samsung Galaxy | 16 | 24.02.2012 23:22 |
| ListView will nicht so recht... | Samsung I7500 | Android App Entwicklung | 9 | 01.09.2009 11:37 |
| SQL Lite Datenbank + ListView | pgnonick | Android App Entwicklung | 26 | 28.08.2009 13:14 |
| ListView Textfarbe | joschika77 | Android App Entwicklung | 26 | 08.07.2009 09:05 |
| Geht nix mehr | DevNull | T-Mobile G1 Forum | 11 | 23.06.2009 18:50 |