Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Fragments overlapping? #23

Closed
nmesisca opened this issue Dec 18, 2014 · 12 comments
Closed

Fragments overlapping? #23

nmesisca opened this issue Dec 18, 2014 · 12 comments

Comments

@nmesisca
Copy link

Hello again,
I implemented your library mostly successfully (thanks, you are doing a great job btw) but when I replace the FragmentIndex of your example with 3 different fragments, what I see is that the fragments overlap? So I can still see fragment1 when I should only see fragment2. You don't see that in your example code because your fragments are all instances of FragmentIndex, so they are identical.
In your implementation, are the fragments added, or are they replacing previous fragments?

thanks for the clarification!

@neokree
Copy link
Owner

neokree commented Dec 18, 2014

Actually Fragments is stored inside your Sections, that is stored in MaterialNavigationDrawer with a LinkedList.
When you tap on a section in your drawer, drawer replace your Fragment.

 if(fragment instanceof android.app.Fragment)
        getFragmentManager().beginTransaction().replace(R.id.frame_container, (android.app.Fragment)fragment).commit();
 else if(fragment instanceof android.support.v4.app.Fragment)
        getSupportFragmentManager().beginTransaction().replace(R.id.frame_container,(android.support.v4.app.Fragment) fragment).commit();

Maybe the problem is that I always replace fragments but I don't remove it.
I dunno very well how fragmentManager works.

@nmesisca
Copy link
Author

Mmm.. so.. if you replace your FragmentIndex with 3 different fragments with different layouts and content, you don't see any overlapping happening?
I am using 3 sections (icon+text), and my init() looks (very simply) like this (I left your fragmentindex for the first 2 sections while the 3rd section uses my custom one):

this.addSection(this.newSection("Overview",this.getResources().getDrawable(R.drawable.ic_search),new FragmentIndex())); this.addSection(this.newSection("Stocks",this.getResources().getDrawable(R.drawable.ic_search),new FragmentIndex()));
this.addSection(this.newSection("Currencies",this.getResources().getDrawable(R.drawable.ic_exchange), new CurrenciesFragment()));

I have taken a couple of screenshots:
the first fragment:
https://www.dropbox.com/s/zta60p8pylwpxn6/Screenshot_2014-12-18-13-33-04.png?dl=0
the second fragment, overlapping with the first.
https://www.dropbox.com/s/dzqsak744e5u4km/Screenshot_2014-12-18-13-33-27.png?dl=0

I would appreciate any help you could give.
thanks a million!

@neokree
Copy link
Owner

neokree commented Dec 18, 2014

I created a sample project that use three fragments with different layout, but my fragments won't overlap each other.
Could you send me a little part of your project in private, so that I can found the problem?

@EdwardvanRaak
Copy link

I have the same problem. It doesn't matter if you replace the fragment with addSection() or just with getFragmentManager().beginTransaction().replace(). It always overlaps the fragments.

Note: My fragments ARE transparent

@neokree neokree added the bug label Dec 18, 2014
@neokree
Copy link
Owner

neokree commented Dec 18, 2014

I have just committed a possibly fix.
Please download manually MaterialNavigationDrawerModule, import it as module in your project and tell me if it works.
My fix consist in removing the old fragment before the replace with the new fragment. Should it work, but I cannot test because I haven't reproduced the bug

@EdwardvanRaak
Copy link

I did not work but I know now how to reproduce the bug.

Change your FragmentIndex to

import android.app.Fragment;

instead of

import android.support.v4.app.Fragment;

(I guess you HAVE to use support fragments when using the library)

@neokree
Copy link
Owner

neokree commented Dec 18, 2014

I have created three fragments that have three different objects in different spaces of the screen.
Now I tried to change to get the overlapping.
I tried using android.app.Fragment and android.support.v4.Fragment, but nothing...
I tried with two different devices running API 17 and 19.
(There are multiple implementations of fragments, if you want to use the old android.app.Fragment is a developer decision, but this library supports both)
I have uploaded my apk project there, please check if you have overlapping problems with them.

@EdwardvanRaak
Copy link

I did some more research. It turns out you need 1 fragment importing support fragment, and another importing the normal one. So different ones for each fragment.

this.addSection(this.newSection("Section 1",new FragmentIndexSupport())); //this one imports android.app.Fragment;
this.addSection(this.newSection("Section 2",new FragmentIndex())); //this one imports android.support.v4.app.Fragment

And yes the APK worked fine on my device running 5.0.1

It kind of makes sense that replace doesn't work like that. So it's not really your fault, just our fault using 2 different kinds of fragments.

@neokree
Copy link
Owner

neokree commented Dec 18, 2014

ok, I'll add a RuntimeException if the section support another type of fragment, I'll release a new version tomorrow.
Thank you @montanax for your help

@neokree neokree closed this as completed Dec 18, 2014
@nmesisca
Copy link
Author

hi guys sorry just home now. Actually, my project is using a v4 fragment (my custom one) and fragmentindex which extends the normal fragment, so it would make sense that @montanax deduction is correct. I will do a couple more tests now and will let you know later. I am available to send you some of my code if it will be needed.

N

@nmesisca
Copy link
Author

yep, confirmed, changing the fragmentindex to a v4 as well (so having them all v4) works fine.
thanks for the help guys and sorry I couldn't be here to help earlier.
(ps @neokree ho notato adesso che sei italiano di biella.. siamo quasi :) compaesani, io sono di cuneo, anche se vivo a Dublino. comunque grazie ancora dell'aiuto. son curioso di vedere come evolverai questa libreria.)

@neokree
Copy link
Owner

neokree commented Dec 19, 2014

hahaha il mondo e' piccolo!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants