我曾嘗試使用頁眉與此代碼:如何使用標準方法將標題用於ListView?
String[] strings=new String[]{"1", "2", "3"};
ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,
strings);
ListView view=(ListView)findViewById(R.id.listView1);
TextView v=new TextView(this);
v.setTextColor(Color.WHITE);
v.setText("122224");
v.setTextSize(15);
v.setId(54);
v.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
view.addHeaderView(v);
view.setAdapter(adapter);
但它不例外工作,擊碎:
01-21 16:52:14.025: E/AndroidRuntime(16625): Uncaught handler: thread main exiting due to uncaught exception
01-21 16:52:14.035: E/AndroidRuntime(16625): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nda.android/com.nda.android.AndroidActivity}: java.lang.ClassCastException: android.view.WindowManager$LayoutParams
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.os.Looper.loop(Looper.java:123)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-21 16:52:14.035: E/AndroidRuntime(16625): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 16:52:14.035: E/AndroidRuntime(16625): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 16:52:14.035: E/AndroidRuntime(16625): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
01-21 16:52:14.035: E/AndroidRuntime(16625): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635)
01-21 16:52:14.035: E/AndroidRuntime(16625): at dalvik.system.NativeStart.main(Native Method)
01-21 16:52:14.035: E/AndroidRuntime(16625): Caused by: java.lang.ClassCastException: android.view.WindowManager$LayoutParams
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.widget.ListView.clearRecycledState(ListView.java:492)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.widget.ListView.resetList(ListView.java:478)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.widget.ListView.setAdapter(ListView.java:420)
01-21 16:52:14.035: E/AndroidRuntime(16625): at com.nda.android.AndroidActivity.onCreate(AndroidActivity.java:98)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-21 16:52:14.035: E/AndroidRuntime(16625): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
01-21 16:52:14.035: E/AndroidRuntime(16625): ... 11 more
請給我一個例子。無論如何,我希望你能幫助我,謝謝你。
什麼是98? – JoxTraex