S
SirMArtin
Gast
Hallo zusammen,
ich habe ein wenig Probleme mit der ListView. Nach einigem Lesen in der Doku bin ich zu folgendem Code gekommen:
ResultViewer.java
result.xml
Führe ich die App nun aus, bekomme ich immer die Fehlermeldung:
Das kann ich mir nicht erklären, da ich ja ne ListView mit der ID "list" habe. Wobei ich das auch Käse finde. Ich hätte ja gern ggf. mehrere ListActivities in meiner App und AFAIK ist die ID in der XML unique innerhalb der App.
Hat einer ne Idee, was ich falsch mache?
SirMArtin
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);
}
}
}
result.xml
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>
Führe ich die App nun aus, bekomme ich immer die Fehlermeldung:
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
Das kann ich mir nicht erklären, da ich ja ne ListView mit der ID "list" habe. Wobei ich das auch Käse finde. Ich hätte ja gern ggf. mehrere ListActivities in meiner App und AFAIK ist die ID in der XML unique innerhalb der App.
Hat einer ne Idee, was ich falsch mache?
SirMArtin