public class MyListActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] items = {"Item 1", "Item 2", "Item 3"}; ArrayAdapteradapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, items); setListAdapter(adapter); } }
public class MyListActivity extends ListActivity { @Override public void onListItemClick(ListView l, View v, int position, long id) { // Handle item click event here } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] items = {"Item 1", "Item 2", "Item 3"}; ArrayAdapterIn this example, we override the onListItemClick method to handle list item click events. This method is called automatically when a user clicks on an item in the list. Here, we can perform any action we want based on the position of the clicked list item. Package Library: This class belongs to the android.app package.adapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, items); setListAdapter(adapter); } }