In my application i have tabs but now i need to add Sherlock Actionbar i know that I need use extends SherlockActivity but early I had FragmentActivity how to fix it ?
public class MainActivity extends SherlockActivity {
Now I have error here beacuse i don't have FragmentActivity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
Error:
The method getSupportFragmentManager() is undefined for the type MainActivity
There is SherlockFragmentActivity, I believe, you can extend from that
Related
I am trying to set up the action bar in an Activity which extends fragment:
public class ItemDescriptionActivity extends FragmentActivity
and this is the fragment:
public class ImageSliderFragment extends Fragment
How can I set it up, I cannot extend AppCompatActivity, thanks for your help
use AppCompatActivity . AppCompatActivity extends FragmentActivity so you can you fragments inside AppCompatActivity.
The class AppCompatActivity is a child class of FragmentActivity. so you can use AppCompatActivity instead of FragmentActivity.
i am developing android application. i extend my class to Tab Activity.
while i am using getActionBar() or getSupportActionBar(), the activity stops working. when i extend my activity to Activity or ActionBarActivity getTabHost() will not work. Any one pls help me. thanks in advance.
Here is my coding.
public class CommonTabActivity extends TabActivity
implements OnTabChangeListener {
TabHost tabHost;
Bundle response = new Bundle();
private Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_common_tab);
....
tabHost = getTabHost();
....
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
you can extend your activity to AppCompatActivity (ActionbarActivity is deprecated now), use tablayout from android design library to show tabs and associate viewpager to tablayout to switch between fragments corresponding to each tab.
your activity layout would be something like this.
android.support.v7.widget.Toolbar
android.support.design.widget.TabLayout
android.support.v4.view.ViewPager
There are plenty of examples available to implement this.
http://www.truiton.com/2015/06/android-tabs-example-fragments-viewpager/
When I call getActionBar throws me: "The return type is incompatible with Activity.getActionBar()"
I know it's a dumb question but I can´t find the solution.
public class ClaseContacto extends Activity{...
...
private void showGlobalContextActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setTitle(R.string.app_name);
}
private ActionBar getActionBar() {
return ( (ActionBarActivity) getActivity() ).getSupportActionBar();
}
...
//More code here
getSupportActionBar()? Are you using the android.support.v7 library?
If so, then extend ActionBarActivity instead of Activity. Then remove the getActionBar() method and Call getSupportActionBar() directly.
You don't need to override getActionBar();
In Activity, you just need to call
getActionBar()
and it will return ActionBar object for you
You can check this tutorial
You need to extend ActionBarActivity from support-v7-appcompat library.
And then you should use getSupportActionBar()
e.g.
public class SampleActivity extends ActionBarActivity {
}
and inside onCreate() function use below code to get action bar :-
ActionBar actionBar = getSupportActionBar();
Make sure you have imported android-support-v7-appcompat library in your IDE and added that as library project in your application project from build path -> android.
I have a SherlockFragmentActivity, this Activity have a SectionsPagerAdapter and a ViewPager. When I call the constructor of the SectionsPagerAdapter with getChildFragmentManager() method, it shows me this error message:
The method getChildFragmentManager() is undefined for the type ViewPagerActivity
This is my code:
public class ViewPagerActivity extends SherlockFragmentActivity implements OnPageChangeListener, OnQueryTextListener{
private SectionsPagerAdapter sectionsPagerAdapter;
private ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_view_pager);
sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager(), this);
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOnPageChangeListener(this);
this.getMovements();
this.getPrizes();
this.getVouchers();
this.createDropdownlist();
}
I'm using ActionBarSherlock and I updated the android-support-v4.jar using "Android Tools - Add Support Library" in my project, also on ActionBarSherlock project.
I'm doing this because I need to have a ListFragment inside a Fragment that I use like a page on my ViewPager.
getChildFragmentManager() is a method on Fragment, not on FragmentActivity. Use getSupportFragmentManager() on a FragmentActivity.
I have a class which creates a behindMenu for a Sliding Menu as follows:
public class BehindMenuFragment extends ListFragment {
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String[] categories = getResources().getStringArray(R.array.categories);
CategoryAdapter adapter = new CategoryAdapter(getActivity());
int cats = categories.length;
for (int i = 0; i < cats; i++) {
adapter.add(new CategoryItem(categories[i], getIcon(categories[i])));
}
setListAdapter(adapter);
}
It gets called from another activity MainActivity with the following code:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame, new BehindMenuFragment ())
.commit();
The above code works fine no problems, I want to insert an Action Bar using ActionBarSherlock to the behind menu I've tried it in every way possible to no avail.
Extending BehindMenuFragment as a SherlockListFragment gives me the following error:
IllegalStateException: BehindMenuFragment must be attached to a SherlockFragmentActivity
Im at a loss and don't know how to move forward with this problem please help!
It appears you haven't done step four:
Setup with ActionBarSherlock
Setup as above.
Checkout a clean copy of ActionBarSherlock and import into your Eclipse workspace.
Add ActionBarSherlock as a dependency to SlidingMenu
Go into the SlidingActivities that you plan on using make them extend Sherlock___Activity instead of ___Activity.
Having never worked with this library I would guess that you should change MainActivity to:
public class MainActivity extends SherlockSlidingFragmentActivity {
Now you can use a SherlockListFragment:
public class BehindMenuFragment extends SherlockListFragment {
And add Sherlock's ActionBar.