简体   繁体   中英

onAttachedToWindow() is not being called

I am creating a object for a class FlyOutContainer like this

this.root = (FlyOutContainer) this.getLayoutInflater().inflate(R.layout.activity_sample, null);

and in the class FlyOutContainer, i have the method onAttachedToWindow()

protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        Log.i("onAttachedToWindow", " occured");
        this.menu = this.getChildAt(0);

        this.content = this.getChildAt(1);

        this.menu.setVisibility(View.GONE);
    }

hoping that this method should be called when i am creating the object for this.root but the method onAttachedWindow() is never get called. Why??

UPDATE1

<com.bibliotheque.android.view.viewgroup.FlyOutContainer xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#444488"
        android:orientation="vertical" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="toggleMenu"
            android:text="@string/home_btn_label" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="toggleMenu"
            android:text="@string/search_btn_label" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="toggleMenu"
            android:text="@string/mybooks_btn_label" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="toggleMenu"
            android:text="@string/contact_btn_label" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="toggleMenu"
            android:text="@string/about_btn_label" />

    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:background="#888888"
        android:orientation="vertical" >

        <LinearLayout

            android:id="@+id/home"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:background="#888888"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hello_world"
                android:textAppearance="?android:attr/textAppearanceLarge" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/search_layout"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:background="#888888"
            android:orientation="vertical" >

            <EditText
                android:id="@+id/searchInput"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="top"
                android:inputType="text" />

            <ListView
                android:id="@+id/bookList"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />           

        </LinearLayout>

    </LinearLayout>

I am using the FlyOutContainer to achieve the Slide in menu

Have you actually added the view to the layout?

You need to call addView(root) on the parent you want to contain your FlyOutContainer, or use the 3 parameter method on the LayoutInflater :

getLayoutInflater().inflate(R.layout.activity_sample, container, true)

where container is, again, the ViewGroup that will contain your new view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM