片段只是ListView
。
Pageadadapter类:
public Fragment getItem(int i) {
if(i==(count-1)){
// The first section of the app is the most interesting -- it offers
// a launchpad into the other demonstrations in this example application.
return new PageAbout();
}
else if(i==(count-2)){
return new ussd();
}
}
错误:
06-14 16:35:10.727 28955-28955/com.buckydroid.app.droidcpu E/InputEventReceiver: Exception dispatching input event.
06-14 16:35:10.727 28955-28955/com.buckydroid.app.droidcpu E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
06-14 16:35:10.735 28955-28955/com.buckydroid.app.droidcpu E/MessageQueue-JNI: java.lang.RuntimeException: com.buckydroid.app.droidcpu.ActivityMain@d04309 must implement OnFragmentInteractionListener
at layout.ussd.onAttach(ussd.java:125)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:779)
at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:802)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:660)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:2050)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2665)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1793)
at android.app.Activity.dispatchTouchEvent(Activity.java:3076)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2626)
at android.view.View.dispatchPointerEvent(View.java:9521)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4104)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3650)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3795)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3677)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3852)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3650)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3677)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3650)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5932)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5906)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5867)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6035)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5471)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-14 16:35:10.735 28955-28955/com.buckydroid.app.droidcpu D/AndroidRuntime: Shutting down VM
06-14 16:35:10.737 28955-28955/com.buckydroid.app.droidcpu E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.buckydroid.app.droidcpu, PID: 28955
Theme: themes:{default=overlay:com.zyxxeil.milos.ui, iconPack:com.zyxxeil.milos.ui, fontPkg:com.zyxxeil.milos.ui, com.android.systemui=overlay:com.zyxxeil.milos.ui, com.android.systemui.navbar=overlay:com.zyxxeil.milos.ui}
java.lang.RuntimeException: com.buckydroid.app.droidcpu.ActivityMain@d04309 must implement OnFragmentInteractionListener
at layout.ussd.onAttach(ussd.java:125)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1019)
at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:779)
at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:802)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:660)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:2050)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2108)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2553)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2197)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2665)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1793)
at android.app.Activity.dispatchTouchEvent(Activity.java:3076)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2626)
at android.view.View.dispatchPointerEvent(View.java:9521)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4238)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4104)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3650)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3795)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3677)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3852)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3650)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3669)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3677)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3650)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5932)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5906)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5867)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6035)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5471)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:1)
只需评论onAttach()函数
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
或实施监听器