簡體   English   中英

找不到ID的資料檢視(針對片段)

[英]No view found for Id (for fragment)

我正在嘗試的是,從我的一個活動中調用一個片段,但是會引發以下錯誤。我知道我不是第一個提出這個問題的人,我已經嘗試了所有與問題相關的解決方案,但沒有任何解決方案可以解決我的問題。

錯誤:

 java.lang.IllegalArgumentException: No view found for id 0x7f08005f (com.aviz.www.reminder:id/mAddAlarm) for fragment AlarmCreater{88da1f5 #0 id=0x7f08005f AlarmCreater}
        at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
        at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2415)
        at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2194)
        at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2148)
        at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2049)
        at android.app.FragmentManagerImpl$1.run(FragmentManager.java:718)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)

mAddIcon是要在其上添加該片段的布局的ID,因此該ID應該在您要從其中添加AlarmCreater Activity / Fragment的布局中。

簡而言之,mAddIcon應該位於您的AlarmActivity布局( R.layout.activity_alarm )上,您可以將其用作FrameLayout / RelativeLayout / LinearLayout

fragment_alarm_creater.xml是片段的布局(視圖)。 因此,無法通過Activity查找mAddIcon。

您可以在R.layout.activity_alarm布局中放置相同的linearLayout。

防爆。 R.layout.activity_alarm使用此xml

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/AppTheme.PopupOverlay">

    <ImageView
        android:id="@+id/mDeleteIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.1"
        android:src="@drawable/ic_delete_sweep_black_24dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="0.8"
        android:text="Alarm"
        android:textColor="@color/tab_background"
        android:textSize="20dp"
        android:textStyle="bold" />

    <ImageView
        android:id="@+id/mAddIcon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="15dp"
        android:layout_weight="0.1"
        android:src="@drawable/ic_add_black_24dp" />
</android.support.v7.widget.Toolbar>

<android.support.v7.widget.RecyclerView
    android:id="@+id/mRecyclerView_id"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>


    <FrameLayout 
        android:id="@+id/mAddAlarm"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"/>
    </LinearLayout>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM