I have implemented a ListActivity, and would like to launch a different intent for each possible selection of the items in the list.
For example:

Clicking on About item should launch an intent with a new activity, and clicking on the Access Phone Gallery item should launch an intent opening the Phone Gallery (for selecting an image say).
I’d like to understand two things:
- How can I determine which item was clicked, so that I can launch the correct
intent? - How can I make the items in the list change style when they are selected? (say become highlighted so that the User Experience is better)
The following is the code of MyActivity (implementing the ListActivity):
public class MyActivity extends ListActivity implements OnItemClickListener
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list_activity);
ListView listView = (ListView) findViewById(android.R.id.list);
listEntryClass listEntries[] = new listEntryClass[]
{
new listEntryClass( "About", "About" ),
new listEntryClass( "Access Phone Gallery", "Access Gallery and Choose an Image" )
};
listEntryArrayAdapter adapter = new listEntryArrayAdapter(this, R.layout.list_entry_layout, listEntries);
View header = (View)getLayoutInflater().inflate(R.layout.list_header_layout, null);
TextView headerValue = (TextView) header.findViewById(R.id.list_header);
headerValue.setText( this.getString(R.string.headerPrefs) );
listView.addHeaderView(header);
listView.setAdapter(adapter);
listView.setOnItemClickListener( this );
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Log.d(TAG, "Clicked an entry");
}
}
I guess there should be something like a switch-case on the id of the clicked item at some place, but have no idea of how to do it.
How can I determine which item was clicked, so that I can launch the correct intent?
How can I make the items in the list change style when they are selected? (say become highlighted so that the User Experience is better)
As for setting the color, you need a
StateListDrawable. You can set this on your list using theandroid:listSelectorattribute, defining the drawable in XML like this: