Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.evolutio.blocklaunch;
- import java.util.ArrayList;
- import java.util.Arrays;
- import android.app.Activity;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- public class ListActivity extends Activity {
- private ListView mainListView ;
- private ArrayAdapter<String> listAdapter ;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- // Find the ListView resource.
- mainListView = (ListView) findViewById( R.id.mainListView );
- // Create and populate a List of planet names.
- String[] planets = new String[] { "Mercury", "Venus", "Earth", "Mars",
- "Jupiter", "Saturn", "Uranus", "Neptune"};
- ArrayList<String> planetList = new ArrayList<String>();
- planetList.addAll( Arrays.asList(planets) );
- // Create ArrayAdapter using the planet list.
- listAdapter = new ArrayAdapter<String>(this, R.layout.item, planetList);
- // Add more planets. If you passed a String[] instead of a List<String>
- // into the ArrayAdapter constructor, you must not add more items.
- // Otherwise an exception will occur.
- listAdapter.add( "Ceres" );
- listAdapter.add( "Pluto" );
- listAdapter.add( "Haumea" );
- listAdapter.add( "Makemake" );
- listAdapter.add( "Eris" );
- // Set the ArrayAdapter as the ListView's adapter.
- mainListView.setAdapter( listAdapter );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement