Welcome to part 17 of my Android Development Tutorial. This is part 2 of my Android Fragments Tutorial series. Part 1 is here and you should watch it before watching this video.
Fragments are often used so you can create completely different interfaces depending upon the screen real estate available. We’ll cover how to do that and we’ll also look at how we can get the fragments to communicate with each other and the main activity. The Whole package is available here Android Fragments.
If you like videos like this, it helps to tell Google+ with a click here [googleplusone]
Code From the Video
lpsum.java
dimens.xml
news_articles.xml
article_view.xml
news_articles.xml (layout-large)
HeadlinesFragment.java
ArticleFragment.java
MainActivity.java
Hey..
Thanks for tutorials. Can you please make one tutorial about AlarmManager and how to set multiple alarms?
I will definitely cover that. Thank you for the request 🙂
Hey…
what is the different btwn app made in JAVA and app made in JAVA EE ..
A Android Java app would be able to take advantage of all the specific Android tools. An app meant to be cross platform would work on more devices, but lose access to those tools specific to either Android or iOS
Master Derek, can you make an android tutorial about reading images? like inputing a string to match the name of the image and if he got the correct string or the name of the image, the user can guess another image again. I hope you understood what I typed, hehe, thanks a million if you’ll make a tutorial of my request, and even if you don’t, thanks for the great tuts 🙂
I have many apps coming out that will be like that. Thank you for the request 🙂
Hey..
Nw amazon has made one tool for developing android app using html5 ..
People say its better den any other tool and easy to make app..
is it true?????
I don’t know what that tool may be? What is it called
hi derek, i know you busy with c tutorials, but i was hoping if u could squeeze in a gesture tutorial for andriod.
thanks for everything.
sbo
Many more Android tutorials are coming. I’m working on the next one right now
why do we need this line of code in MainActivity.java
firstFragment.setArguments(getIntent().getExtras());
i didn’t get this point, since we are not using any intents here.
It grabs anything stored when we switched from one activity to another
but we are not using any passed arguments in the headlines fragment so whats the need to set the arguments
I wnt to know frm u derek..
That phone gap is much easier or directly frm eclipse its will be easier for us to develope android app..
Hi Derek,
Thanks for the awesome tutorials, are you going to be posting some more android stuff? I’m trying to figure out the process of an android app interacting with a restful service, will you be covering that?
You’re very welcome 🙂 Yes more Android tutorials are coming. I’ll get them out ASAP. I covered how to use the Yahoo restful service for XML and JSON early in the tutorial. I will cover how to create webservices soon.
My (humble) requests are
swipe
animations (simple game)
rotation handling
Thanks for all your wonderful material!
The next video will cover animation as well as touch. Thank you for the requests and you are very welcome 🙂
Hey …love the tutorials so helping me learn android …gat a sem project that i have to make a fashion app could you plse cover colour selection ..would be so helpfull thanks man
I’m going to spend more time on interface design soon. Sorry the videos are taking so long. I’m trying to make sure each one is good. I have been throwing a bunch of the videos out.
Master, I’m from Nicaragua and I do not know if you speak spanish but if you do let me know and if you do not, it is ok, Because I’m learning it, well I got a question in the tutorial number 3 I made and follow all the step for the app, but at the end of running the app to my device, which is a tablet mediapad 7 lite, an error appears like the app “crazytipcalc has stopped”, and the option ok to exit, I do not know was the problem is, and thank you for the tutorials is a such a wonderfull website
Thank you 🙂 I speak a little Spanish, but I use a translator if I need to.
As per your question, what errors are you getting in the LogCat panel in Eclipse? (Window -> Show View -> Other… -> Android -> LogCat)
è°¢è°¢ä½ ã€‚
Thanks
æ¡è¿Žæ‚¨çš„光臨
Hello Derek, thank you so much for the amazing tutorials. Do u know how to make Dictionary app. Where people can type word like “computer’ and get the meaning/definition of computer. I would like to make English to my native language dictionary and it is very important. I have been following your tutorials hoping i would learn how to make dictionary app at least in the end. Could you please teach me how to do that? thank you very much.
I actually was going to make an app that would act as a universal translator. My approach was to build the translations using the Grammatical Framework.
The app quickly got out of control, teaching wise, so I had to drop the idea for a tutorial. You could definitely make a translation app this way though. I’d be very interested in what you come up with.
I hope that helps 🙂
Hello Derek,
Thanks for ur kind reply. Sadly i have very basic knowledge of programming. Could u point me to other source links if u know. I have all the list of 5000 words and meaning already in excel file. I need some way to extract this file when people make query in app form. Thanks you.
Hello Henry,
If you have the words translated you could just save them in table form in an SQLite database. SQLite is some what like a spreadsheet. I have a tutorial on SQLite. Then when they type in a word, you can find the proper word next to it in the chosen language and display it in a text box.
Stick with it. I’m sure you can do it.
Hello Derek,
Thank you very much. I will work on that. And thanks for all the great tutorials.
You’re very welcome 🙂
Salut Derek,
The first, I really love your videos. Thank you for your sharing!
And second, i have problem with this fragment tutorial. I try to code by myself or copy direct your source codes to my eclipse but it’s still not worked …!
The application force close when i try to open it
This is logcat error:
E/AndroidRuntime(2197): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030003
I think have some problem with onCreate method in MainActivity. But i can’t fix it. I tried clean project and then restart eclipse. I didn’t find any answer from google or stackoverflow also. Could you help me please ! Thanks again.
Hi Max,
I have the whole Android Package here. Try the code there. I think the problem may be that a lot of the auto-update things that work with my setup aren’t working for others. I use Eclipse Indigo for Java Developers with the Android plugin like I show in my Install Android Development Tools tutorial.
I hope that helps 🙂
Thank you so much ! it saved me a lot of times. I found out my problem. It’s typo name of xml layout so, the onCreate method cannot setContentView for the application. Oh brain …
That’s funny 🙂 I’m glad you figured it out. I’ve spent many hours pulling my hair out over typos.
Hi Derek,
Thank you for the wonderful tutorials and you are the best.
I am wondering if you have or will you be covering tabs in future. I have not covered all tutorials yet could you please let me know the number if you did.
Thank you very much,
Adam
Hi Adam,
I will definitely cover tabs. The current video since part 18 are going to be all about making interfaces.
Why do I keep getting this error very frequently?! “The specified activity does not exist! Getting the launcher activity.”
The codes are exactly the same.
Make sure you check the Deploy application checkbox in the Run/Debug Configuration screen, under the General tab.
But I would like to point out one thing I noticed. Now a days your video tutorials like this one is very very fast you use copy paste of code a lot and you are damm fast.
For instance I need to pause this video after each minute to write out the codes you have written.
of course you have provided the code along with comments but still I like to make programs along with live video tutorials so please if you can slow down, In this video you were really too fast and it was not at all enjoyable writing with you
Thnx for providing these awesome tutorials
I’m constantly working to find the perfect speed for the tutorials. Thank you for the input. I’ll try to improve.
Hey, Your tutorials study materials are awesome, I don’t have words to thank u. The content of your video tutorials are just amazzzing.
Hey Derek why not make a wonderful app, at the end of which there is also a walk through to upload it to google play store. ( Please do not choose google maps as the major app video tutorial – it sucks ).
Thnks anyway
Eventually I’m going to great apps to go along with the video tutorials. So for example if I do an algebra tutorial I will make an Algebra practice app. I plan to do this over and over again. That way I can teach how to make real world Android apps while I continue to explore new areas of knowledge. Everything will be free 🙂
Thank you for the kind words 🙂 I try to do my best.
First of all thanks for your tutorial.
To test this app on my Galaxy S4, I replaced layout-large by layout-land. But when I select an article in land layout, I have a NullPointerException in updateArticleView because article was not found.
Is it a little bug or is it because it has to be implemented another way when one uses layout-land ?
Thanks in advance for your answer.
Gilles
Paris
Sorry, but I’m not sure if I tested that or not. i need to make more videos on interface design.
I really wanna understand this tutorial. But everything seem not very easy to be understood for me. teacher Derek, can you tell me how to understand this source codes fully please? Thank you very much
Tell me what specifically is confusing and I’ll answer each question one by one.
Hello Derek, what is the preferable resolution for this lab. My first emulator is to small to have these landscape changes. Then I changed to a Nexus 10 with a 2560*1600 it’s so big that it only has the landscape. Thanks for very good tutorials.
Hello Ricky, I have my emulator settings on this page http://www.newthinktank.com/2013/04/solving-android-sdk-problems/. I also cover how to install the newest Android tools here.
I’m trying to figure out fragments… and this example still leaves me with a question.
* When this app is started on a large device, the first entry to source code is to onAttach in HeadlinesFragment.java
* When this app is started on a small device, the first entry to source code is to onCreate in MainActity.java
Ok – I understand if the large layout is used, it calls fragments, and if the smaller layout is used, well, it isn’t used until MainActivity.java inflates it.
So, why/how does android know that if using the large xml, to call using the fragment lifecycle (which starts with onAttach in HeadlinesFragment.java), and if using the small device, to use the activity lifecycle (that starts with onCreate in MainActivity.java).
Thanks in advance for your help.
And by the way… FANTASTIC TUTORIALS!!!!!!!!!!!!
Thank you 🙂 The easiest thing to do is to watch my newest Android tutorials on Fragments. I covered them much better this time. I hope they help.
Ok… figured it out. My previous post isn’t exactly accurate… so this is what I found out.
When run on a large device, the order of what is run is:
* MainActivity.java, onCreate starts
when setContentView is executed, the following gets run:
* HeadlinesFragment.java, OnAttached gets called
* HeadlinesFragment.java, OnCreate gets called
* ArticleFragment.java, OnCreateView gets called
* MainActivity.java, onCreate ends
* HeadlinesFragment.java, onStart gets called
* ArticleFragment.java, onStart gets called
* Tablet screen now shows both fragments.
On the other hand, a much different path happens if a SMALL device screen is run:
* MainActivity.java, onCreate starts
* if statement starts FragmentManager and begins Fragment.add…
* MainActivity.java, onCreate ends
* HeadlinesFragment.java, onAttach is called
* HeadlinesFragment.java, onCreate is called
* HeadlinesFragment.java, onStart is called
* Phone screen now shows headlines fragment only.
So what it comes down to is: When setContentView is called, if the layout contains fragments (as in the large device), the fragments get started. If setContentView does not contain fragments (as in the small device), nothing was started, so the Activity needs to start the fragments it wants/needs.
I now see it’s obvious… now…
Again – FANTASTIC TUTORIALS!!!
Thanks – Daniel
Thank you for writing that out 🙂 I’m sure it will help others. I’m glad you are enjoying the videos.