1

我有一个扩展FrameLayout为分页“向导”视图中的适配器提供视图的类。通常,要将片段添加到 a FrameLayout,我只需使用

getSupportFragmentManager().beginTransaction().replace()

将我的片段添加到布局中。但是,当我尝试像在这里一样添加片段时:

public class ReviewPreviousInspectionStep extends FrameLayout implements IWizardStep {
    private IWizardStepStatusChangedListener listener;
    private FragmentActivity activity;

    public ReviewPreviousInspectionStep(FragmentActivity activity) {
        super(activity);

        this.activity = activity;
        LayoutInflater.from(activity).inflate(R.layout.review_previous_inspection, this, true);

        InspectionHistoryFragment inspectionHistoryFragment = new InspectionHistoryFragment();
        inspectionHistoryFragment.setRetainInstance(true);

        activity.getSupportFragmentManager().beginTransaction()
                .replace(R.id.historyFragmentContainer, inspectionHistoryFragment, "historyFragment")
                .addToBackStack("historyFragment")
                .setTransition(FragmentTransaction.TRANSIT_ENTER_MASK)
                .commit();
    }

    //snip
}

FragmentActivity同样,该视图从方法中的适配器添加到活动(我已设置为从 扩展) getView

当我运行它时,我得到以下异常:

 Caused by: java.lang.IllegalArgumentException: No view found for id 0x7f0a002d for fragment InspectionHistoryFragment{41983b08 #0 id=0x7f0a002d historyFragment}
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:864)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
        at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
        at roboguice.activity.RoboFragmentActivity.onStart(RoboFragmentActivity.java:60)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1163)
        at android.app.Activity.performStart(Activity.java:5018)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2032)
        ... 11 more

那么有没有办法以这种方式将片段添加到自定义控件?

4

0 回答 0