Android Development Tutorial 6

Android Development TutorialWelcome to part 6 of my Android Development Tutorial! Over the next few videos I will cover a tremendous amount of information. You can get the whole app right now if you can’t wait here Android Stock Quote App.

Here are just a few of the things I’ll cover over the next few videos: The TableLayout : Dynamically Fill ScrollViews : Save Key / Value Pairs : Review of ClickListeners : Using Intents to Open other Applications : Alert Dialog Boxes : Start other Activities and Pass in Information : Yahoo Web Service : YQL : AsyncTask : Threads : Parsing XML 

If you like videos like this, it helps to tell Google+ with a click here [googleplusone]

Code From the Video

strings.xml

colors.xml

dimens.xml

activity_main.xml

stock_quote_row.xml

34 thoughts on “Android Development Tutorial 6”

  1. I copied these files over so i can listen more while you explain, and none of my things are style like yours is in the video. None of the things are centered, it would be a great help if you could help me out with this. Thank you for the great tutorials

    1. actually its only when i create it in the same workspace as the other apps we have made previously.

      1. You should try to watch the video and actually do everything yourself following Derek.
        I’ve done so and the layout of my app and that of the app described in the tutorial match perfectly (normally, the workspace folder that is set shouldn’t matter).

        Take the time to write the code yourself instead of just copying everything – I’m sure you know these two are very different things in terms of learning.

        1. There is android:gravity=”center” and android:layout_gravity=”center”. You sometimes have to set them both to get the center effect.
          android:layout_gravity=”center_vertical android:gravity=”center_vertical”

    1. duplicate the tableRow1 in activity_main.xml at line 013 and 087.
      and TableLayout in activity_main.xml at line 076 need android:id=”@+id/stockTableScrollView”

      1. Hello Derek,
        there is a small bug on stock_quote_row.xml
        the right code is
        android:id=”@+id/stockSymbolTextView”

  2. Seems that there are problems here

    081

    You don’t have here id but in the next tutorial you do something like

    // Table inside the scroll view that holds stock symbols
    // and buttons
    private TableLayout stockTableScrollView;

    // in onCreate
    stockTableScrollView = (TableLayout) findViewById(R.id.stockTableScrollView);

  3. Hi Derek
    Let me first complement and thank you for the superb job you are doing. Now about the run time error “android.widget.ScrollView cannot be cast to android.widget.TableLayout”, which many people encounter on your StockQuotes tutorial. Sophie had the same problem but She did not explain the problem and the solution well enough. The issue is that on your tutorial #6 You have :

    That is to say you assign an id to “ScrollView” but you don’t assign an id to “TableLayout”. It turns out, it should be the other way around. You need to assign the id to the “TableLayout” and not to “ScrollView”. So the solution for those who get the above mentioned run time error is that they must remove the id from “ScrollView” and assign it to “TableLayout” as follows:

    That should take care of the problem.

    Mike

  4. For some reason the code did not show up in my previous comment. About: Run-time error “android.widget.ScrollView cannot be cast to android.widget.TableLayout”.

    The wrong way: Pay attention to id lines.

    ScrollView
    android:id=”@+id/stockTableScrollView”
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:layout_span=”2″
    android:padding=”5dp”

    TableLayout
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:padding=”5dp”
    android:stretchColumns=”yes”
    TableLayout

    The right way: Pay attention to id lines.

    ScrollView
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:layout_span=”2″
    android:padding=”5dp”

    TableLayout
    android:id=”@+id/stockTableScrollView”
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:padding=”5dp”
    android:stretchColumns=”yes”
    TableLayout

    Mike

  5. Hi Derek
    Let me first complement and thank you for the superb job you are doing. Now about the run-time error “android.widget.ScrollView cannot be cast to android.widget.TableLayout” which many people encounter on your StockQuotes tutorial #6 and beyound. Sophie had the same problem but She did not explain the problem and the solution well enough. The issue is that on your tutorial #6 You have :

    The wrong way:

    ScrollView
    android:id=”@+id/stockTableScrollView”
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:layout_span=”2″
    android:padding=”5dp”

    TableLayout
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:padding=”5dp”
    android:stretchColumns=”yes”
    TableLayout

    ScrollView

    That is to say you assign an id to “ScrollView” but you don’t assign an id to “TableLayout”. It turns out, it should be the other way around. You need to assign the id to the “TableLayout” and not to “ScrollView”. So the solution for those who get the above mentioned run-time error is that they must remove the id from “ScrollView” and assign it to “TableLayout” as follows:

    The wrong way. Pay attention to id lines

    ScrollView
    android:id=”@+id/stockTableScrollView”
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:layout_span=”2″
    android:padding=”5dp”

    TableLayout
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:padding=”5dp”
    android:stretchColumns=”yes”
    TableLayout

    ScrollView

    The correct way. Pay attention to id lines

    ScrollView
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:layout_span=”2″
    android:padding=”5dp”

    TableLayout
    android:id=”@+id/stockTableScrollView”
    android:layout_width=”match_parent”
    android:layout_height=”wrap_content”
    android:padding=”5dp”
    android:stretchColumns=”yes”
    TableLayout

    ScrollView

    Mike

    1. Hi Mike,

      Ill have to look into that. Thank you for the input 🙂

      Some people seem to have the same problem because they are entering a comma in the price amount. I guess that is common in other countries?

      I didn’t have time to cover everything and provide 100% error checking. Sorry about that.

  6. Not sure if you mention the manifest file but, the quote button wouldn’t work until I set the permission for the device to use the internet in the android manifest xml.

  7. can u pls show me the what is the use of jquerymobile and jqueryui and how to use them in our project or app…

  8. Hi Derek ,

    thank you for these great tutorials, I make my debut in programming for android and they are very helpful to me . However, I currently have a problem with the interface. When I desire to center the text in the textView , I use the command android : gravity = ” center_horizontal ” but when I look at the interface, the text is shifted to the right. I feel I should set limits . If I understand correctly, the android command: layout_width = ” match_parent ” defined limits .

    ex:

    < TextView
                android: id = "@ + id / stockSymbolTextView "
                android: layout_width = " match_parent "
                android: layout_height = " wrap_content "
                android: layout_span = "2"
                android: gravity = " center_horizontal "

    Currently I use Android Developer Tools Build : 887826 v22.3.0 – one Pc and win7

    All updates have been made.

    Are you already seen this?

    Thank you . I hope you can help me.

    Alex .

    1. Hi Alex,

      Thank you for the kind compliment 🙂 Relative layouts can some times not work perfectly. Have you tried android:gravity=”center”

      You may also want to try messing with weight if you are still having problems.

      Tell me if that doesn’t work
      Derek

  9. Hi Derek,

    Love the tutorials. Thanks for spending the time to teach us newbies! I have watched tutorials 6 – 8 for the multiple activity stock quote picker and I still can’t get it working.

    Do I need to edit the android manifest aswell? I couldn’t find it in the code you posted. The application just seems to crash as soon as I run it. Also, do I need to use a specific build? I’m using 4.0.3.

    Thanks for your help!
    Dan

    1. Hi Dan,

      Sorry, but I think Yahoo changed their data. You’ll have to look at it and use the different tags they now use. I’ll be making an updated web services tutorial in the next week. That will allow everything to always work and also teach how to make your own web services.

Leave a Reply

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