简体   繁体   English

onAttachedToWindow()没有被调用

[英]onAttachedToWindow() is not being called

I am creating a object for a class FlyOutContainer like this 我正在为这样的FlyOutContainer类创建对象

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

and in the class FlyOutContainer, i have the method onAttachedToWindow() 在类FlyOutContainer中,我有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. 希望当我为this.root创建对象时应调用此方法,但是永远不会调用onAttachedWindow()方法。 Why?? 为什么??

UPDATE1 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 我正在使用FlyOutContainer来实现“滑入”菜单

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 : 您需要在要包含FlyOutContainer的父对象上调用addView(root) ,或在LayoutInflater上使用3参数方法:

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

where container is, again, the ViewGroup that will contain your new view. 同样, container是将包含新视图的ViewGroup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 何时在Layouting Process中调用onAttachedToWindow - When is onAttachedToWindow called in the Layouting Process Android是否可以在调用onAttachedToWindow()时隐藏状态栏? - Android Can we hide status bar when onAttachedToWindow() is called? Android 视图 - onAttachedToWindow 和 onDetachedFromWindow - 它们在活动生命周期中何时被调用? - Android view - onAttachedToWindow and onDetachedFromWindow - when are they called in the activity lifecycle? 相当于 RecyclerView 中 ViewHolder 的 onAttachedToWindow()/onDetachedFromWindow() - Equivalent of onAttachedToWindow()/onDetachedFromWindow() for a ViewHolder in RecyclerView Android,如何定义onAttachedToWindow()方法? - Android, how to define onAttachedToWindow() method? 视图未附加到onAttachedToWindow中的窗口管理器 - View not attached to window manager in onAttachedToWindow 在OnAttachedToWindow(...)中,GetWindowVisibleDisplayFrame()对于所有尺寸均返回0 - in OnAttachedToWindow(…), GetWindowVisibleDisplayFrame() returns 0 for all dimensions 详细的android活动生命周期(onAttachedToWindow()) - Detailed android activity lifecycle (onAttachedToWindow()) 无法可靠地调用UtteranceProgressListener - UtteranceProgressListener not being reliably called 未调用OnClick方法 - OnClick Method is not being called
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM