package com.example.cgoncalves.listviewapp.ListViewAndroidExample.ListViewAndroidExample;  import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView; import android.view.View; import android.widget.Toast;  /**  * Created by cgoncalves on 29.08.2014.  */ public class ListViewAndroidExample extends Activity {     ListView listView ;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_list_view_android_example);          // Get ListView object from xml         listView = (ListView) findViewById(R.id.list);          // Defined Array values to show in ListView         String[] values = new String[] { "Android List View",                 "Adapter implementation",                 "Simple List View In Android",                 "Create List View Android",                 "Android Example",                 "List View Source Code",                 "List View Array Adapter",                 "Android Example List View"         };          // Define a new Adapter         // First parameter - Context         // Second parameter - Layout for the row         // Third parameter - ID of the TextView to which the data is written         // Forth - the Array of data          ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,                 android.R.layout.simple_list_item_1, R.id.text1, values);           // Assign adapter to ListView         listView.setAdapter(adapter);          // ListView Item Click Listener         listView.setOnItemClickListener(new OnItemClickListener() {              @Override             public void onItemClick(AdapterView<?> parent, View view,                                     int position, long id) {                  // ListView Clicked item index                 int itemPosition     = position;                  // ListView Clicked item value                 String  itemValue    = (String) listView.getItemAtPosition(position);                  // Show Alert                 Toast.makeText(getApplicationContext(),                         "Position :"+itemPosition+"  ListItem : " +itemValue , Toast.LENGTH_LONG)                         .show();              }          });     }  }