【发布时间】:2014-07-09 17:56:43
【问题描述】:
我正在尝试在活动加载时扩展自定义视图,然后对该视图的子元素执行某些操作。下面我尝试膨胀视图,然后在布局 XML 中获取对 TextView 的引用以更新文本值。但是在下面的代码中,在最后一行之后,actionBarTitle 为空 - 当我希望它是对 TextView 的引用时。我做错了什么?
Activity onCreate() 方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_userseed);
LayoutInflater inflator = LayoutInflater.from(this);
actionBarView = inflator.inflate(R.layout.fragment_actionbar_viewseed, null);
TextView actionBarTitle = (TextView) actionBarView.findViewById(R.id.action_bar_title);
}
还有布局 XML
<?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>
【问题讨论】:
标签: android