[英]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.