如何实现一个文件浏览器,而不扩展listactivity类?我试图在我的应用程序中添加一个选项,选择一个文件浏览器来选择自己的文件使用,而不是默认的。我做了一个按钮,移动到文件浏览器列表,但是当我使用代码setListAdapter(ArrayAdapter);
它说我需要扩展ListActivity。当我这样做,我有一个问题运行应用程序。知道我做错了什么吗?我怎么能不扩展listactivity,因为我的应用程序不仅仅是一个列表,它只需要使用列表。谢谢!
UPDATE-LOGCAT
01-15 09:39:22.399: D/AndroidRuntime(317): Shutting down VM
01-15 09:39:22.409: W/dalvikvm(317): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-15 09:39:22.409: E/AndroidRuntime(317): Uncaught handler: thread main exiting due to uncaught exception
01-15 09:39:22.429: E/AndroidRuntime(317): java.lang.IllegalStateException: Could not execute method of the activity
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.View$1.onClick(View.java:2031)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.View.performClick(View.java:2364)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.View.onTouchEvent(View.java:4179)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.widget.TextView.onTouchEvent(TextView.java:6541)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.View.dispatchTouchEvent(View.java:3709)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-15 09:39:22.429: E/AndroidRuntime(317): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-15 09:39:22.429: E/AndroidRuntime(317): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-15 09:39:22.429: E/AndroidRuntime(317): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.os.Looper.loop(Looper.java:123)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-15 09:39:22.429: E/AndroidRuntime(317): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 09:39:22.429: E/AndroidRuntime(317): at java.lang.reflect.Method.invoke(Method.java:521)
01-15 09:39:22.429: E/AndroidRuntime(317): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-15 09:39:22.429: E/AndroidRuntime(317): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-15 09:39:22.429: E/AndroidRuntime(317): at dalvik.system.NativeStart.main(Native Method)
01-15 09:39:22.429: E/AndroidRuntime(317): Caused by: java.lang.reflect.InvocationTargetException
01-15 09:39:22.429: E/AndroidRuntime(317): at phil.H.com.HIITActivity.changesong(HIITActivity.java:132)
01-15 09:39:22.429: E/AndroidRuntime(317): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 09:39:22.429: E/AndroidRuntime(317): at java.lang.reflect.Method.invoke(Method.java:521)
01-15 09:39:22.429: E/AndroidRuntime(317): at android.view.View$1.onClick(View.java:2026)
01-15 09:39:22.429: E/AndroidRuntime(317): ... 21 more
01-15 09:39:22.429: E/AndroidRuntime(317): Caused by: java.lang.NullPointerException
01-15 09:39:22.429: E/AndroidRuntime(317): at phil.H.com.HIITActivity.getDir(HIITActivity.java:216)
01-15 09:39:22.429: E/AndroidRuntime(317): ... 25 more
01-15 09:39:22.509: I/Process(59): Sending signal. PID: 317 SIG: 3
01-15 09:39:22.509: I/dalvikvm(317): threadid=7: reacting to signal 3
01-15 09:39:22.609: I/dalvikvm(317): Wrote stack trace to '/data/anr/traces.txt'
01-15 09:44:22.559: I/Process(317): Sending signal. PID: 317 SIG: 9
01-15 09:44:22.659: E/JavaBinder(59): !!! FAILED BINDER TRANSACTION !!!
01-15 09:44:22.680: I/WindowManager(59): WIN DEATH: Window{44debcc8 phil.H.com/phil.H.com.HIITActivity paused=false}
01-15 09:44:22.680: I/ActivityManager(59): Process phil.H.com (pid 317) has died.
01-15 09:44:22.939: I/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in phil.H.com
01-15 09:44:23.559: W/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 317 uid 10029
您不必使用ListActivity
。只要在布局中使用正确的方法,就可以在布局中使用ListView
对象。
在您膨胀的XML文件中设置ListView
,然后获取它:
ListView myListView = (ListView) findViewById(R.id.my_list);
然后,你可以设置它的适配器:
myListView.setAdapter(ArrayAdapter);
文档中有一个关于中等高级ListView
实现的很棒的教程。