在ViewPager中实施什么更好?
OR
我用过两者都有自己的缺点。
第1个问题。
第二个问题。
logcat的
E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.widefide.musicplayer, PID: 14058
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.widefide.musicplayer/com.widefide.musicplayer.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
at com.widefide.musicplayer.Fragments.Playlists.PlaylistsFragment.onActivityCreated(PlaylistsFragment.java:72)
at android.support.v4.app.Fragment.performActivityCreated(Fragment.java:1797)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:979)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1120)
at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1929)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
at com.widefide.musicplayer.MainActivity.onStart(MainActivity.java:127)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1236)
at android.app.Activity.performStart(Activity.java:6006)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2288)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3947)
at android.app.ActivityThread.access$900(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:2)
在第一中,您可以通过通知父fragment
来替换Activity
,而Activity
会将fragment
替换为其他fragment
Toolbar
}}。您仍然可以从Activity
控制interface
。您可以default fashion(使用activity
)或使用Bus events (Otto
)
在第二中,我更喜欢这样,您可以轻松打开onBackPressed
,并可以通过lscm status
或fragment backstack控制您的背压。
答案 1 :(得分:0)
从第一个案例的第一个问题可以看出,你想要一个新的屏幕,那么最好是一个新的活动。第二个解决方案中的问题似乎是一个错误,发布代码以便我们可以解决它。
答案 2 :(得分:0)