Android 充气后找不到自定义视图的子元素
我正在尝试膨胀活动负载的自定义视图,然后对该视图的子元素执行一些操作。下面我尝试放大视图,然后在布局XML中获取对TextView的引用,以更新文本值。然而,在下面的代码中,在最后一行之后,actionBarTitle为null——我希望它是对TextView的引用。我做错了什么 Activity onCreate()方法 以及布局XMLAndroid 充气后找不到自定义视图的子元素,android,Android,我正在尝试膨胀活动负载的自定义视图,然后对该视图的子元素执行一些操作。下面我尝试放大视图,然后在布局XML中获取对TextView的引用,以更新文本值。然而,在下面的代码中,在最后一行之后,actionBarTitle为null——我希望它是对TextView的引用。我做错了什么 Activity onCreate()方法 以及布局XML <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="ht
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/actionbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp" />
<android.support.v4.view.ViewPager
android:id="@+id/actionbar_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/actionbar_pagerstrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.view.ViewPager>
</LinearLayout>
试试:
TextView actionBarTitle=(TextView)actionBarView.findViewById(R.id.actionbar_title)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/actionbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp" />
<android.support.v4.view.ViewPager
android:id="@+id/actionbar_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTitleStrip
android:id="@+id/actionbar_pagerstrip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.view.ViewPager>
</LinearLayout>