Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Introduction to Android Fragments Tutorial

Discover how to break your complex layouts into manageable chunks in this Android fragments tutorial!


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1427-introduction-to-android-fragments-tutorial

I liked her style. Great explanation.Thanks

1 Like

Thanks for the great tutorial!

minor remark: I followed along, right after adding the to fragment to the activity’s XML layout, the resulting screen does not show the text below the picture of Freddy Mercury. The xml tag is ‘tools:text’, which is just a placeholder text, if I replaced this with android:text=“Freddie …”, then the text appeared

Just a friendly heads up, the link at the bottom of the page: “Adaptive UI with Android Layouts” links back to the same page (Intro to Fragments) instead of to the actual Adaptive UI tutorial.

Otherwise, I really appreciate these tutorials. They’re super helpful! I look forward to seeing more Android App tutorials in the future. Maybe one for Android Auto?

Thanks so much for this tutorial! Simple and clean. This is just an awesome material!

Thank you so much for this article. By the way, are you Vietnamese ? :heart_eyes:

Thanks @whasssaaahhh - I was wondering what I did wrong :slight_smile:

This issue should have been fixed by now. Don’t know why it’s not fixed yet :frowning:

Hi all. Apologies for the delay in updating the project. I thought I had updated an updated starter project but I have now made sure that the issue with the “tools:text” attribute is resolved.

Sorry again about that. I really thought I had updated the project.

I also updated the project to the latest release versions of the Android gradle plugin, support repositories, and build tools. Please note that I did not update the build to Android N version just yet.

@designwolf I also fixed the link at the bottom of the tutorial. Thanks for the heads up.

I went through this tutorial almost completely without issue but when I tried to complete the last time (updating the onRageComicSelected() method in MainActivity.java, I get an error. Specifically, it’s with the .replace() call. When I try to run the project, I get:

Error:(48, 13) error: no suitable method found for replace(int,RageComicDetailsFragment,String)
method FragmentTransaction.replace(int,Fragment,String) is not applicable
(actual argument RageComicDetailsFragment cannot be converted to Fragment by method invocation conversion)
method FragmentTransaction.replace(int,Fragment) is not applicable
(actual and formal argument lists differ in length)

I went through the last bit of code again to see if I missed something but I can’t figure out what. My RageComicDetailsFragment.java has the extends Fragement part which means it should work, right?

@kinadian Can you paste the imports at the top of your MainActivity here? So my first guess without seeing more of your code is that there might be a discrepancy on which Fragment.

So there is the core Fragment (android.app.Fragment) and there is the support Fragment (android.support.v4.Fragment). I sometimes import both by accident and they are not interchangeable.

If this is not the issue, I can maybe look at your class and see if there is something else.

@queencodemonkey MainActivity.java doesn’t have any Fragment imported. However, your reply led me to figure out the cause of the problem.

I was importing android.app.Fragment in RaceComicDetailsFragment.java instead of android.support.v4.app.Fragment.

Great tutorial. There is a line in recycler_item_rage_comic.xml that should be fixed, otherwise the grid cells height take up the entire screen.

Hi,
Thanks for the tutorial. How could I add a Navigation Drawer to this example and be able to have fragments/screens with different layouts? (I’m creating an app with about 4 different “main screens”, i.e. Navigation Menu items. Some of the “main screens” will have sub screens, different layouts, buttons, forms, etc. )