Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package com.javatechig.droid.ui;
  2.  
  3. import android.os.Bundle;
  4. import android.app.Activity;
  5. import android.widget.ArrayAdapter;
  6. import android.widget.ListView;
  7.  
  8. public class ListActivity extends Activity {
  9.  
  10.     // Initialize the array
  11.     String[] monthsArray = { "JAN", "FEB", "MAR", "APR", "MAY", "JUNE", "JULY",
  12.  "AUG", "SEPT", "OCT", "NOV", "DEC" };
  13.  
  14.     // Declare the UI components
  15.     private ListView monthsListView;
  16.  
  17.     private ArrayAdapter arrayAdapter;
  18.  
  19.     /** Called when the activity is first created. */
  20.     @Override
  21.     public void onCreate(Bundle savedInstanceState) {
  22.         super.onCreate(savedInstanceState);
  23.         setContentView(R.layout.activity_list);
  24.  
  25.         // Initialize the UI components
  26.         monthsListView = (ListView) findViewById(R.id.months_list);
  27.         // For this moment, you have ListView where you can display a list.
  28.         // But how can we put this data set to the list?
  29.         // This is where you need an Adapter
  30.  
  31.         // context - The current context.
  32.         // resource - The resource ID for a layout file containing a layout
  33.                 // to use when instantiating views.
  34.         // From the third parameter, you plugged the data set to adapter
  35.         arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, monthsArray);
  36.  
  37.         // By using setAdapter method, you plugged the ListView with adapter
  38.         monthsListView.setAdapter(arrayAdapter);
  39.     }
  40. }