簡體   English   中英

IllegalArgumentException:找不到片段id的視圖

[英]IllegalArgumentException: No view found for id for fragment

我正進入(狀態

11-13 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.makemyday/com.example.makemyday.ActionDetailActivity}:java.lang.IllegalArgumentException: No view found for id 0x7f050007 (com.example.makemyday:id/action_detail_container) for fragment ActionDetailFragment{41e9add8 #0 id=0x7f050007}

action_detail_activity的代碼

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_action_detail);

        if (savedInstanceState == null) {

            Bundle arguments = new Bundle();
            String id= getIntent().getStringExtra(ActionDetailFragment.ARG_ITEM_ID);
            arguments.putString(ActionDetailFragment.ARG_ITEM_ID, id);
            ActionDetailFragment fragment = new ActionDetailFragment();
            fragment.setArguments(arguments);
            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
            ft.add(R.id.action_detail_container, fragment);

            SupportMapFragment mapFragment;
            ImageFragment imageFragment;
            Toast.makeText(this, ActionDetailFragment.ARG_ITEM_ID, Toast.LENGTH_SHORT).show();

            if(id.equalsIgnoreCase("1"))
            {
                Toast.makeText(this, "here1", Toast.LENGTH_SHORT).show();
                //mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
                //map=mapFragment.getMap();
            }
            else if(id.equalsIgnoreCase("2"))
            {
                Toast.makeText(this, "here2", Toast.LENGTH_SHORT).show();
                //imageFragment = (ImageFragment) getSupportFragmentManager().findFragmentById(R.id.picture_upload);
                imageFragment=new ImageFragment();
                ft.add(R.id.imageContainer, imageFragment);

            }

            ft.commit();              
        }
    }

activity_action_detail.xml的代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+android:id/outer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" 
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame">

    <FrameLayout
            android:id="@+android:id/action_detail_container"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    <FrameLayout
            android:id="@+android:id/imageContainer"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />


        <Button
            android:id="@+id/start_time_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="from" />

</LinearLayout>

請有人回答這個問題

嘗試這個..

不需要使用@+android:id for framelayout只需要fragement listview需要@+android:id

對於linearlayout也使用

android:id="@+id/outer_container"

<FrameLayout
            android:id="@+id/action_detail_container"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    <FrameLayout
            android:id="@+id/imageContainer"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

編輯:

@+android:id表示你指的是android命名空間中定義的FrameLayout @+id定義您自己的Id到視圖。

非常好..這也救了我.. android:id =“@ + id / container”

在我的代碼中丟失了。

暫無
暫無

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

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