1 / 15

07.1. Event Handling

07.1. Event Handling. Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 oum_saokosal@yahoo.com. Agenda. XML-based Event Handling Java-based Event Handling More Event Listeners. XML-based Event Handling. XML-based Event Handling (1). 1.

season
Download Presentation

07.1. Event Handling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 07.1. Event Handling Prof. OumSaokosal Master of Engineering in Information Systems, South Korea 855-12-252-752 oum_saokosal@yahoo.com

  2. Agenda XML-based Event Handling Java-based Event Handling More Event Listeners

  3. XML-based Event Handling

  4. XML-based Event Handling (1) 1 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="Show Me!" android:id="@+id/btnShowMe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="showMe" /> </LinearLayout>

  5. XML-based Event Handling (2) 2 packagecom.kosalab; importandroid.app.Activity; importandroid.os.Bundle; importandroid.view.View; importandroid.widget.Toast; publicclassWidgetContainerextends Activity { publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eventhandling); } publicvoidshowMe(View v){ Toast.makeText(this, "This event invoked from XML.", Toast.LENGTH_SHORT).show(); } }

  6. Java-based Event Handling

  7. Java-based Event Handling (1) 1 ?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="Show Me!" android:id="@+id/btnShowMe" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>

  8. Java-based Event Handling (2) 4 2 3 5 publicclassWidgetContainerextends Activity implements OnClickListener{ Button btn; publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eventhandling); btn = (Button)findViewById(R.id.btnShowMe); btn.setOnClickListener(this); } publicvoidonClick(View v) { Toast.makeText(this, "It's Toast Message! It appears shortly.“, Toast.LENGTH_SHORT).show(); } }

  9. Java-based Event Handling – Another Example

  10. 2 1 3 4 publicclassWidgetContainerextends Activity implementsOnClickListener, OnLongClickListener{ Button btn; publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.eventhandling); btn = (Button)findViewById(R.id.btnShowMe); btn.setOnClickListener(this); btn.setOnLongClickListener(this); } publicvoidonClick(View v) { Toast.makeText(this, “Short click!“, Toast.LENGTH_SHORT).show(); } publicbooleanonLongClick(View v) { Toast.makeText(this, “Long click!", Toast.LENGTH_SHORT).show(); returntrue; } }

  11. onLongClick() – return true/false publicbooleanonLongClick(View v) { Toast.makeText(this, “Long click!", Toast.LENGTH_SHORT).show(); returntrue; } Note: return true: show only the longClick. return false: show both longclick and then short click.

  12. More Event Listeners onFocusChange() From View.OnFocusChangeListener. This is called when the user navigates onto or away from the item, using the navigation-keys or trackball. onKey() From View.OnKeyListener. This is called when the user is focused on the item and presses or releases a key on the device. onTouch() From View.OnTouchListener. This is called when the user performs an action qualified as a touch event, including a press, a release, or any movement gesture on the screen (within the bounds of the item). onCreateContextMenu() From View.OnCreateContextMenuListener. This is called when a Context Menu is being built (as the result of a sustained "long click").

  13. Go on to the next slide

More Related