Handling User Selections

You handle the user's selecction by setting the class's AdapterView.OnItemClickListener member to a listener and catching the selection changes.

// Create a message handling object as an anonymous class.

private OnltemClickListener mMessageClickedHandler = new OnItemClickListener() {

public void onItemClick(AdapterView parent, View v, int position, long id) {

// Display a messagebox.

Toast.makeText(mContext,"You've got an event",Toast.LENGTH_SHORT).show(); }

// Now hook into our object and set its onltemClickListener member // to our class handler object.

mHistoryView = (ListView)findViewByld(R.id.history); mHistoryView.setOnltemClickListener(mMessageClickedHandler);

For more discussion on how to create different AdapterViews, read the following tutorials: Hello Spinner, Hello ListView, and Hello GridView.

0 0

Post a comment