getSupportActionBar() is always return null!Please Help

591 views
Skip to first unread message

johnson_z

unread,
Sep 11, 2012, 10:32:27 PM9/11/12
to actionba...@googlegroups.com

@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);
setContentView(R.layout.rc_hd_main);

Resources res = getResources();
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
LocalActivityManager lam = new LocalActivityManager(this, false);
lam.dispatchCreate(savedInstanceState);
tabHost.setup(lam);
TabHost.TabSpec spec;
spec = tabHost.newTabSpec("favs")
.setIndicator("Favorites", res.getDrawable(R.drawable.rc_main_menu_sharefile))
.setContent(new Intent().setClass(this, FileTransferMainActivity.class));
tabHost.addTab(spec);

// add tabs to tab host
spec = tabHost.newTabSpec("search")
.setIndicator("Search", res.getDrawable(R.drawable.rc_main_menu_touchpad))
.setContent(new Intent().setClass(this, TouchPadActivity.class));
tabHost.addTab(spec);

spec = tabHost.newTabSpec("lenses")
.setIndicator("Lenses", res.getDrawable(R.drawable.rc_main_menu_ppt))
.setContent(new Intent().setClass(this, PptPatternActivity.class));
tabHost.addTab(spec);

}

I'm trying to use actionbar&viewpager in FileTransferMainActivity.But getSupportActionBar() is always return null.I can'n move forward with my app if i won't solve the problem.please help.
Always i had set the application with style :Theme.Sherlock.

Jonathan Steele

unread,
Sep 12, 2012, 2:28:30 AM9/12/12
to actionba...@googlegroups.com
What FileTransferMainActivity extends to?

Jake Wharton

unread,
Sep 12, 2012, 2:29:57 AM9/12/12
to actionba...@googlegroups.com
You cannot use ABS with ActivityGroup and/or LocalActivityManager. Use fragments if you need logic to be encapsulated around views.

---
Jake Wharton
http://about.me/jakewharton

张健新

unread,
Sep 12, 2012, 4:18:24 AM9/12/12
to actionba...@googlegroups.com
First,thanks for your response.
I'm sorry I didn't explain my problem clearly. FileTransferMainActivity (extends SherlockFragmentActivity) actually contains three fragments.
My app crashed down in the red color part(Shown below,from  FileTransferMainActivity).The previous code I send to you is From MainTabActivity. I can use FileTransferMainActivity with actionbar separately but i can't use it in the case of adding the FileTransferMainActivity as one tab of tabhost.Is that I can't use ABS in such situation.
I am Looking forward to your reply!My English is not good,I hope you can understand what i write. Thank you.

@Override
protected void onCreate(Bundle paramBundle) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(paramBundle);
setContentView(R.layout.rc_transfer_file_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
init();
}


private void init() {
                getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.rc_main_online));

getSupportActionBar().setTitle(getString(R.string.rc_main_connection_state_online));

getSupportActionBar().setDisplayShowHomeEnabled(false);

getSupportActionBar().setDisplayUseLogoEnabled(false);

getSupportActionBar().setDisplayShowTitleEnabled(false);

mLayoutInflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

mViewPager = (ViewPager) findViewById(R.id.rc_transfer_file_main_pagers);

mMainAdapter = new FileTransferMainAdapter(getSupportActionBar(), this, mViewPager);

mMainAdapter.addTab(getString(R.string.rc_filetransfer_main_tab_file), R.drawable.rc_filetransfer_main_tab_file, NewShareFilesFragment.class, null);

mMainAdapter.addTab(getString(R.string.rc_filetransfer_main_tab_category), R.drawable.rc_filetransfer_main_tab_category,
NewCategoryFilesFragment.class,
null);

mMainAdapter.addTab(getString(R.string.rc_filetransfer_main_tab_uploadList), R.drawable.rc_filetransfer_main_tab_uploadlist,
NewUploadProgressListFragment.class, null);

mViewPager.setAdapter(mMainAdapter);

}

2012/9/12 Jake Wharton <jakew...@gmail.com>

张健新

unread,
Sep 12, 2012, 4:24:56 AM9/12/12
to actionba...@googlegroups.com
First ,Thanks for your response!
 FileTransferMainActivity (extends SherlockFragmentActivity) actually contains three fragments. I can use FileTransferMainActivity with actionbar separately but i can't use it in the case of adding the FileTransferMainActivity as one tab of tabhost.Is that I can't use ABS in such situation.
I am Looking forward to your reply!My English is not good,I hope you can understand what i write. Thank you.

2012/9/12 Jonathan Steele <xfsu...@gmail.com>
What FileTransferMainActivity extends to?

Abdul Aleem Mohammed

unread,
Nov 7, 2012, 2:52:04 PM11/7/12
to actionba...@googlegroups.com
Hi Jake,

I m trying to use ActionBarSherlock in my application. I m using ActivityGroups for my tabs and i want to show actionBar for one fo the activity in tabs. I m able to to display menus but whenever i call getSupportActionBar().setNavigationMode(getSupportActionBar().NAVIGATION_MODE_LIST); i m getting Null pointer exception.

Any help will be appreciated.

Thanks 

Regards
Abdul
Reply all
Reply to author
Forward
0 new messages