Android Development Tutorial 7

Get the Code Here:

Best Android Book :

Welcome to part 7 of my Android Development Tutorial! Today I will continue what I started in the last part of this tutorial series. 30 Minutes Packed With Information!

I cover how to do all of the following:

1. Pass values between activities
2. Save key value pairs
3. Use OnClickListeners
4. Retrieve saved data
5. Use ScrollViews
6. Use Alert Dialog Boxes
7. Use Intents to Open Applications
8. Use Intents to Open Activities
9. Force Close the Keyboard
and, Much More…






43 responses to “Android Development Tutorial 7”

  1. jayan chandran Avatar

    Derek you are great

  2. almania69 Avatar

    will you consider making a Material Design tutorial?

  3. Anirudh Upadhyayula Avatar

    Hi Derek,

    I remember in the tip calculator tutorial you did earlier you did not use SharedPreferences to store the data but saved the data as a bundle when the program is out of focus so that it can retain it when resuming the program. Is there a difference between the two or are they essentially the same thing but done differently.


  4. Saugat Singh Avatar

    wondering if you have a tutorial for parsing JSON data, please consider target SDK as 23 because some classes from previous versions are dropped 🙂

  5. Rui Peng Avatar

    I cannot run the codes

  6. Life soul Avatar

    import Thanks.showAppreciation;

    public class thankful{
    Me me = new Me.ThankYou(Good tutorials);}

  7. Sathyaprakash Narayanan Avatar

    do we need to know the basic java to learn android i know a bit of c++ but not java !!

  8. Peter Möhrenbart Avatar

    I have a question about this method:

    private void saveStockSymbol(String newStock) {

            String isTheStockNew = stockSymbolsEntered.getString(newStock, null);
            // WHY do you check whether the stock symbol is not yet in the list, but then
                        // do the following Editor stuff no matter whether it already is?
            SharedPreferences.Editor preferencesEditor = stockSymbolsEntered.edit();
            preferencesEditor.putString(newStock, newStock);

            if(isTheStockNew == null) {

    Basically: Why is it necessary to make an editor and add the newStock even if it's already contained in SharedPreferences stockSymbolsEntered? Maybe I don't understand what a SharedPreferences.Editor does, in that case what does it do here?

    And one more question: android.content.SharedPreferences seems to be only an interface and the methods have no implementations. Will they be implemented later on in the tutorial, or are they defined somewhere I didn't find?
    Thanks very much in advance!

  9. Donglai Jiang Avatar


    for EditText, you put a Private,
    for Button, you didnt define any access type, public or private.
    may i know why?


  10. Donglai Jiang Avatar

    thanks for the great video.

    btw, may i ask what is the tool you were using for quickly zoom in and zoom out the screen view?

  11. kam hagh Avatar

    Stocklist is just a name you gave to your saved stuff right?

  12. Andrew McCarter Avatar

    Hey Derek, awesome tutorials, they're really helping not only guide what I want to do but motivating me to actually doing it! However, is there anywhere in you videos that you go over how to create a simple sign in screen on an app that you could have username and password or sign in with facebook?

  13. Brian Hanford Avatar

    Hey Derek, thanks for the great tutorials. I do not have an file or a gen folder. I was wondering if there was a download I might have missed or something.  Thanks for any help.

  14. Marcus Lee Avatar

    Thank you Sir provide a good tutorial.

  15. Ali Erdoğan Avatar

    I watched the whole video. Thank you 🙂

  16. Ed Jenkins Avatar

    Good Tutorial – Thanks

  17. moby boy Avatar

    sorry pal, Ive totally lost you. this is not just copy paste to me, it seems that we need to know many commands in order to unserstand how to do it by ourselves , but I understand your meaning 🙂

  18. Mitja Oven Avatar

    Why is EditText in this video private but Buttons aren't? I'm kinda throwing them in the sam basket so i don't see the necessity for marking one private and the other one not. Thanks for answering

  19. Peter Xu Avatar

    What's the difference between AlertDialog.Builder and AlertDialog?

  20. Silas Mcfarlane Avatar

    Can I just up something random for the package. Like com.silas.stockquote Or do I have to have a website?

  21. Abhishek Balani Avatar

    I watched till the end.

  22. beteljuse beteljuse Avatar

    Excellent videos! Late getting to this series. Have an issue! Using Android 4.? with Luna Eclipse. Error in Main with your code entry…
    (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)!
    Keep getting this error ->LAYOUT_INFLATER_SERVICE cannot be resolved or is not a field????? Cannot locate relative documentation online that explains this. ANY CLUES? Thanks and keep up the good work.

  23. Frank Gonzalez Avatar

    Derek you're awesome. Of all the tuts on Youtube (and I've seen a lot) yours are the best!

  24. Kidus Tiliksew Avatar

    Hi there, really enjoying your tutorial. One question — where did stockTableScrollView at 07:18 come from? I went back and reviewed tutorial 6 and don't see who's id that is.

  25. Chris Sun Avatar

    Hi Derek,
       thx for all of these videos. Adding on to my last question, in the intent constructor, you put the calling activity, MainActivity as MainActivity.this and the called activity, StockInfoActivity, as StockInfoActivity.class. What is the significance of this?

  26. Chris Sun Avatar

    hi Derek, I noticed for the alertdialog.builder constructor, you put MainActivity.this as the argument. Would this be fine as well as it refers to the current executing activity(MainActivity)? Or does MainActivity.this have some special meaning?

  27. feitingschatten1 Avatar

    Newbies, pay attention. This guy sets up his data structures so well that his error messages literally mark what he has to do next. Also note, his variables are named so clear, that he's not confused at what part he needs to put in next.

    If that doesn't sound impressive, remember he can name his listeners anything. When you go to code this yourself, don't let that slip by.

    You've got good habits, and it's good you're teaching 'em.

  28. Carlos Ferreira Avatar

    I watched the whole video 😛

  29. M Gilissen Avatar

    insertStockInScrollView(newStockSymbol, Arrays.binarySearch(stocks, newStockSymbol));

    How does this make sure the newStockSymbol is added in the array in sorted order? Could you explain briefly what Arrays.binarySearch does in this situation?

  30. G3ForceX Avatar

    I really liked the tutorial, especially how you explained the whole thing about getting the string of the stocksymbol at 28:00. Didn't really get it the first time. Repeating stuff like that really makes it a whole lot easier to understand and memorize it.

  31. Herp Derpingson Avatar

    Double click on a word to select it instantly 🙂

  32. Ятвойдед Avatar

    Why do you alweys write EditText areas in the MainActivity class? Is it important?

  33. ray xu Avatar

    String[] stocks = stockSymbolsEntered.getAll().keySet().toArray(new String[0]);
    what does the ”new String[0]“ means here.

  34. kyleD Avatar

    I think with the recent changes to Eclipse, whenever you click the "Add unimplemented methods" for the OnClickListeners, instead of generating the class that you have (public void OnClick(View v) ) it now creates a class called "public void onClick(DialogInterface dialog, int which)".  This is an issue because I can't use v.getParent() when calling the tablerows like you do in your code.  Also, I can't just change the auto generated code to match your's because I get the "unimplemented method" error.

  35. Alex King Avatar

    Man you need to slow down! I spend half of the time pausing the video just to type and figure it out! Haha but nice tutorials, I'm learning alot. ☺

  36. Michael Hirooka Avatar

    Great tutorial! The only problem for me is that I get confused with the id names!

  37. Luis Colondres Avatar

    Hi Derek, just a quick question: how come the same items change id's from video to video and the complete code? or maybe I'm looking at it wrong…. 

  38. Andy Avatar

    My question:

    If I decided to define the getStockActivityListener and getStockFromWebsiteListener click listeners inline (inside of the insertStockInScrollView method), then couldn't I just get the stock symbol from the string "stock" that is passed into the insertStockInScrollView method, and use it in the inner classes for the click listeners? That way I wouldn't have to get the TableRow and the TextView from it.  Would this be a viable solution?

    Thanks by the way for all your videos, they are extremely well done!

  39. amit goyal Avatar

    Hi, the video refers to
    stockTableScrollView = (TableLayout) findViewById(;
    but, inside the video we never created stockTableScrollView.
    Due to this, I am receiving ScrollView can not be cast to TableTayout exception.

    Please help!!!!!

  40. zaft1g337 Avatar

    the explanation at 29 mins made me like this video 😀 ty for ur effort!!

  41. rwoz Avatar

    I don't get it… now I changed this by adding ID to the linearlayout and refering to its ID instead of the scrollviews, and it worked… why didn't you do that? Why do that strange thing by refering to the scrollviews ID? 

  42. rwoz Avatar

    When I try to create a linearlayout by refering it to a scrollview I get ClassCastException: android.widget.ScrollView cannot be cast to android.widget.LinearLayout

  43. Joseph Butewicz Avatar

    Some people were not able to find onClick(View v) so here is the likely solution.

    When you imported the OnClickListener class you imported DialogInterface.OnClickListener instead of View.OnClickListener.

    To fix this problem remove "import android.content.DialogInterface.OnClickListener;" and then mouse over OnClickListener and select "import 'OnClickListener' (android.view.View)". This will add the "import android.view.View.OnClickListener;" class. Then mouse over OnClickListener and click "Add unimplemented methods" and you will see "onClick(View v)" instead of "onClick(DialogInterface dialog, int which)".

    Huge thanks to Derek on all of the awesome hard work that you put into these tutorials. They are a huge help to many people.


Leave a Reply

Your email address will not be published. Required fields are marked *