CS251L - Fall 2012

Intermediate Programming

Section 002


Jan Monterrubio

Email: janmonterrubio@gmail.com

Office: FEC 3rd Floor Lounge or (FEC 309)

Office Hours:

Wednesday 3 - 5 PM

Friday 2 - 4 PM

Full TA and Tutor Schedule

If these times don't work email me and I'll make sure you get the help you need.


Simple File Reader!

December 4th, 2012

Background

This lab is the beginning of a 2 parter. In this first part, we will simply read from a file and display the text items in a list.

Files at the end

Layout

MainActivity

  1. Start by having private references to the following:
    • ListView listView
    • ArrayList<String> items
    • ArrayAdapter<String> adapter
  2. get the reference to list view
  3. instantiate items
  4. call the parseText() method . We will write this later
  5. instantiate adapter. Remember! this, android.R.layout.simple_list_item_1, items.
  6. set adapter to notify data set change

parseText method

Scanner scanner = null
try{
scanner = new Scanner(getAssets().open("todos.txt"));
}catch(Exception e){}
while(scanner.hasNextLine())
items.add(scanner.nextLine();

Submission

Once again, no submissions, only for your benefit

End Product