Handling User Selections

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

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

private OnItemClickListener 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 onItemClickListener member // to our class handler object.

mHistoryView = (ListView)findViewById(R.id.history); mHistoryView.setOnItemClickListener(mMessageClickedHandler);

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

" Back to User Interface ! Go to top

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

Site Terms of Service - Privacy Policy - Brand Guidelines

OODPOID

develo

User Interface >

Common Layout Objects

This section describes some of the more common types of layout objects to use in your applications. Like all layouts, they are subclasses of ViewGroup.

Also see the Hello Views tutorials for some guidance on using more Android View layouts.

0 0

Post a comment