我已经在片段活动中实现了 viewpager。这个片段活动包含两个滑动片段。要在操作栏中设置片段的标题,我已在片段活动中完成此操作。
mViewPager.setOnPageChangeListener(new OnPageChangeListener()
{
public void onPageSelected(int position)
{
//**this is line68 where error is occuring**
getActionBar().setTitle(mAppSectionsPagerAdapter.getPageTitle(position).toString());
}
但是,我不太清楚如何设置两个片段的标题。在片段中我已经这样做了。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.patient_list, container, false);
getActivity().setTitle("All Patients");
我得到了空指针异常...
06-05 23:54:26.269: E/AndroidRuntime(6430): FATAL EXCEPTION: main
06-05 23:54:26.269: E/AndroidRuntime(6430): java.lang.NullPointerException
06-05 23:54:26.269: E/AndroidRuntime(6430): at com.example.actionbar.MainActivity$1.onPageSelected(MainActivity.java:68)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:538)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:523)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:1943)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.view.View.dispatchTouchEvent(View.java:7340)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2181)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1914)
06-05 23:54:26.269: E/AndroidRuntime(6430): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2187)
请帮忙。