i need help for this . I realize sth very strange about this. In order to disable the Action bar (Title) , i need to add in this code
requestWindowFeature(Window.FEATURE_NO_TITLE);
So this only works I change from
extends AppCompatActivity
To this
extends Activity
So after changing that, I got error for the getFragmentManager.
Please have a look at the screenshot. And let me know if u guys have any idea wads going on? THx
Use getSupportFragmentManager() instead of getFragmentManager().
AppCompatActivity is v4 library therefore required to use v4 functions
And to use it in Activity instead of Activity change it to FragmentActivity. Then you can use getSupportFragmentManager()
requestWindowFeature() is not supported in AppCompatActivity thats why you could not use that method with AppCompatActivity.
Also if you are using AppCompatActivity you need to use SupportFragment and if you use Activity then use Fragment.
If you are using this import import android.support.v4.app.Fragment;,
then you must use getSupportFragmentManager.
Hope this helps.
You have to use the Compat method getSupportFragmentManager() instead of the regular one.
That's because it returns an object of type android.app.FragmentManager which is the type of the object where you're trying to store it.
If you use the regular method getFragmentManager() it'll return an object of type android.app.FragmentManager, which is an incompatible type.
Related
I am trying to get instance of the dynamically currently appearing or showing fragment as follows:
fragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainer);
but this code returns the following type android.support.v4.app.Fragment
and later I want to remove that fragment which I earlier obtains an instance of as follows:
mFragmentTransaction.remove(fragment);
but this method does not accept this type android.support.v4.app.Fragment
How to solve this issue please.
Your variable mFragmentTransaction should be initialized with the getSupportFragmentManager().beginTransaction() method. Maybe you have used the getFragmentManager() object, witch would be incorrect in your case.
Check your imports. If you see the following import:
import android.app.Fragment;
you will want to change it to the support library version to maintain consistency as follows:
import android.support.v4.app.Fragment;
Check your import statements and be sure you are not mixing "Support" fragments and "Native" fragments. You must use a consistent fragment and many recommend the "Support" version over the "Native" version, in which case you should be using getSupportFragmentManager.
Also, since you wish to remove a fragment, make sure the fragment container is not hard coded in XML. If you intend to replace or remove a fragment, then the initial fragment should be loaded dynamically by your code (you typically will load into a FrameLayout using the id as yourR.id.{frameLayoutId}), else it will not work.
I'm having a problem in setting up the activity as: setSupportActionBar(toolbar);
method cannot be resolved.
can anyone help with it.
and yes I had already imported android.support.v7.widget.Toolbar;
Please verify that in your Activity you imported android.support.v7.widget.Toolbar instead of android.widget.Toolbar.
In addition verify your Activity inherits from AppCompatActivity instead of ActionBarActivity since google has deprecated it.
It seems that setSupportActionBar() method cannot be resolved because you may have extended AppBarActivity instead use.
public class MainActivity extends AppCompatActivity{
I have the same issue has this post: android.support.v4.app.Fragment: undefined method getChildFragmentManager(). I need to use getChildFragmentManager() because I'm using nested fragments.
My problem is: the solution in the other post does not work for me:
My SDK is updated.
I got my android-support-v4 from the SDK folder.
I added android-support-v4 both the my project and ABS.
Here is my libs:
How can I correctly use this method?
Not sure if you've resolved your issue yet, but I was having the same issue and I resolved it. The getCildFragmentManager() method is a method of the class Fragment and not FragmentActivity. Just because your class extends fragment activity does not mean you'll have access to this method. What I did is I created an instance of my fragment in which I wanted to place the child fragment and invoked the method through that fragment instance. There are obviously other approaches to this, but this worked for me.
maybe something in your android manifest, look at the header or 'footer of your android manifest about minimum SDK version.
This is because by using old android.support.v4.
once you change the latest library.it will solved
I solved it by change it.
Hope it will work
I'm look for the easiest way to get an ActionBar instance from a Fragment using AppCompatLibrary and API 8.
Already tried things like
getActivity().getSupportActionBar()
but no luck.
Try to cast it:
((YourActivity)getActivity()).getSupportActionBar()
I have a bit of a problem here; I want to use the SlidingMenu on my activity + the ViewPagerIndicator ... but I cannot use the getsupportfragmentmanager() without extending FragmentActivity or I cannot use getSlidingMenu() without extending SlidingActivity..
Is there any work arround to use getsupportfragmentmanager() without extending FragmentActivity or it isn't even possible?
Thanks in advance
(If anyone is interested ill post the code)
EDIT:
I solved the problem;
I went to SlidingActivity.java in the library and changed "extends Activity" to "extends FragmentActivity" and it worked..