Advertisement
Guest User

Untitled

a guest
Mar 29th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.67 KB | None | 0 0
  1. package com.evolutio.blocklaunch;
  2.  
  3. import java.util.ArrayList;  
  4. import java.util.Arrays;  
  5.  
  6. import android.app.Activity;  
  7. import android.os.Bundle;  
  8. import android.widget.ArrayAdapter;  
  9. import android.widget.ListView;  
  10.  
  11. public class ListActivity extends Activity {  
  12.    
  13.   private ListView mainListView ;  
  14.   private ArrayAdapter<String> listAdapter ;  
  15.    
  16.   /** Called when the activity is first created. */  
  17.   @Override  
  18.   public void onCreate(Bundle savedInstanceState) {  
  19.     super.onCreate(savedInstanceState);  
  20.     setContentView(R.layout.activity_main);  
  21.      
  22.     // Find the ListView resource.  
  23.     mainListView = (ListView) findViewById( R.id.mainListView );  
  24.  
  25.     // Create and populate a List of planet names.  
  26.     String[] planets = new String[] { "Mercury", "Venus", "Earth", "Mars",  
  27.                                       "Jupiter", "Saturn", "Uranus", "Neptune"};    
  28.     ArrayList<String> planetList = new ArrayList<String>();  
  29.     planetList.addAll( Arrays.asList(planets) );  
  30.      
  31.     // Create ArrayAdapter using the planet list.  
  32.     listAdapter = new ArrayAdapter<String>(this, R.layout.item, planetList);  
  33.      
  34.     // Add more planets. If you passed a String[] instead of a List<String>  
  35.     // into the ArrayAdapter constructor, you must not add more items.  
  36.     // Otherwise an exception will occur.  
  37.     listAdapter.add( "Ceres" );  
  38.     listAdapter.add( "Pluto" );  
  39.     listAdapter.add( "Haumea" );  
  40.     listAdapter.add( "Makemake" );  
  41.     listAdapter.add( "Eris" );  
  42.      
  43.     // Set the ArrayAdapter as the ListView's adapter.  
  44.     mainListView.setAdapter( listAdapter );        
  45.   }  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement