Bug in android.support.v4.app.FragmentManager? - android

Hi fellow android developers,
I'm trying to implement a multi-pane layout as described here and an example implementation can be found in the codesample "HoneycombGallery".
The only thing I changed is, that instead of using the normal getFragmentManager() I use the support-libraries and therefore the "getSupportFragmentManager()". But now I have the following problem:
The getSupportFragmentManager().findViewById() returns a reference to a fragment even when the fragment is not on the screen :/
As you cann easily see, the example implementation uses this technique to differ between the to possibilyties, but the getSupportFragmentManager() returns a reference to a fragment in situations (for example after a orientation change and the second fragment disappeared as it is no longer in the layout) where it shouldn't.
Has anyone also tried to get Multi-Pane-Layout working with the support-Fragments and FragmentManager?
Any hint is highly appreciated :)
Cheers
Ali3n
PS.: I could post some code if requested, but it actually is nearly the same code as in the example ...

I fixed my problem, by not asking the FragmentManager for the fragment, instead I ask my layout for the view.

I had the same problem and registered an issue on Android issue tracker.
http://code.google.com/p/android/issues/detail?id=40796
Please star if anyone having this issue.

Related

what is fragment activity in android studio?

I'm new to android. i have huge confusion on handling fragments. i'll be pleased if anyone suggest me to know about handling fragments in android? It'll be very helpful.
Thanks in advance.
I needed to use fragments to!
What I do is that I have a FrameLayout inside the activity_main.xml and then I replace the Framelayout with the fragment I want.
If you search here in StackOverflow there's so much information about it.

Tab layout swipe direction

Can I change the swipe direction of Tabs in TabLayout by code?
It works fine when my device's language is English, But when I change it to Arabic, A lot of tabs disappear and the swipe's direction still the same (to The Right ).
Note: In Manifest file support RTL option is "true".
You can easily change layoutDirection. i had this problem too and fix by :
tabLayout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
Just try it!
There are two simple steps you need to follow:
Change the rotation of the View pager,
viewpager.setRotationY(180);
Then again change the direction of the fragment container which is the child of viewpager,
recyclerView.setRotationY(180);
The actual problem you facing is the fact, that ViewPager still does not support RTL.
It's well-known and very old issue - you can find it in Google's issue tracker:
ViewPager RTL swipe direction
So far, I haven't seen any successful examples of RLT's implementation. For, example, there's one from Booking.com, but it doesn't work with TabLayout yet. I'd suggest to dig into it and try to fix the issue there, than start writing it from scratch.
UPD: I forked Booking's RtlViewPager and fix it for TabLayout's. Feel free to try it!
This issue is well known and there is no ETA for a fix.
Use this code tabLayout.setTabMode(TabLayout.MODE_FIXED);

Accordion / ExpandableListView on Android

I'm trying to create an accordion in Android that has the following features:
Slide animation when opening a tab
Alignment to the top when opening a tab
The ability to be used inside a fragment and not inside an activity
Any idea to how to accomplish all these points? I've seen a lot of libraries that however luck of one or more of this points (and I cannot fix the remaining myself :( ).
Any idea? Also pointers to how-to-guides to how to fix the missing points would be really useful! Thanks
If you are interested on how I solved the problem, you can find the code here: https://github.com/filnik/AndroidSmoothAccordion
It is "quick-and-dirty" but it does the job.

Navigation Drawer implies nested fragments?

I created an application with a navigation drawer navigating following the android documentation tutorial. Now the main parts of my application are Fragment but the problem is I have to use dynamic fragments in one of them.
I saw the nested fragments were supported since android 4.2, but I need to use my app on older version.
What can I do ?
I'm thinking of using a FrameLayout of fixed fragments and to set them visible or gone depending of what I need, but it seems a little ugly...
What do you think ?
Thanks for your answers
Edit :
my question is not clear but what I want to know is :
can I use the navigationdrawer with activities instead of fragments ?
is the solution I'm thinking about realy ugly ?
how can I use the nested fragment system for older version ?
In the end I used the nested fragment system using the Android Support Library (thanks Nobu Games)
Thanks for your comments

Problems implementing tabs in ActionBarSherlock 4

I really want to get this to work, but I feel like I've been floundering about for hours. I'm starting up a new app and want to try to follow the UI guidelines as close as possible, which for anything below ice-cream sandwich seems to mean I need to use ActionBarSherlock. Looking at the example here it looks like it should be straightforward.
I try to implement it and it doesn't work because FragmentActivity does not have a getSupportActionBar() method.
Taking a look at the demo app and it seems they don't use FragmentActivity, they use SherlockActivity. Well, SherlockActivity does have a getSupportActionBar() method, so that's promising. Continuing on with the example for a while...
Okay, now it seems the com.actionbarsherlock.app.ActionBar.TabListener doesn't pass FragmentTransaction to its events? Not only that, but the SherlockActivity doesn't have a getSupportFragmentManager() method...
Am I (hopefully) just doing something completely wrong? How do I keep encountering all these issues that no one else is? I feel like I'm going nuts here. The only potentially related issue I've found is here and it's not very useful.
You need to extend from SherlockFragmentActivity instead of only SherlockActivity or SherlockFragment. This way you will get access to ABS and the Fragment Support.
I ran into a similar problem trying to get a map view and fragments to work with actionbarsherlock. See my post on the mailing list.
The solution I came up with was to get the sources for the compatibility library and modify the FragmentActivity to extend a SherlockActivity instead of a standard android Activity.
Then you'll need to compile the sources for the support library along with your app(in some fashion).
In my case I went an additional step to modify the SherlockActivity to extend MapActivity, but since you didn't mention maps, you wouldn't need to do that.
There may be other solutions, but this at least got things to work for me.
I would recommend the mailing list as this project seems to be changing frequently.
Try to use extend from com.actionbarsherlock.app.SherlockFragmentActivity and take a look at https://github.com/inazaruk/examples/tree/master/MapFragmentExample to see how to use a Map with Fragments.

Categories

Resources