title: How to initialize a listview
body: <p>Why is this so difficult to do</p>
  
  <p>I have a simple listview. When a row is pressed it is highlighted and stays highlighted until another row is pressed.
  Also when a row is pressed I get some data from the row and show it in a toast. This is all working perfectly.
  What I can not do is when the listview is started, I want the first row to be highlighted automatically and the toast message shown just as if the first row was pressed.
  Does anyone have an example of how this can be done.</p>
  
  <p>Here is my code:
  public class MainActivity extends Activity
      {
      ListView listView;
      private View lastview = null;</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState)
      {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      listView = (ListView) findViewById(R.id.list);
  
      String[] values = new String[] { "Row 1", 
                                       "Row 2",
                                       "Row 3",
                                       "Row 4", 
                                       "Row 5", 
                                       "Row 6", 
                                       "Row 7", 
                                       "Row 8" 
                                      };
  
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
        android.R.layout.simple_list_item_1, android.R.id.text1, values);
      listView.setAdapter(adapter); 
  
      listView.setOnItemClickListener(new OnItemClickListener()
          {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id)
              {
              if ( lastview != null )
                  lastview.setBackgroundColor(Color.WHITE);
              lastview = view;
              view.setBackgroundColor(0xcc0022cc);
  
              String  content  = (String) listView.getItemAtPosition(position);
              Toast.makeText(getApplicationContext(), String.format("&lt;%d&gt;&lt;%s&gt;", position, content), Toast.LENGTH_LONG).show();
              }
          }); 
      }
  
  
  
  }
  </code></pre>