1 / 8

Designing user interfaces using: Simple views

Designing user interfaces using: Simple views. Views. Basic views TextView EditText Button ImageButton CheckBox ToggleButton RadioButton RadioGroup Spinner. Pickers TimePicker DatePicker Normally added to DialogFragment Lists ListView ListActivity ListFragment. View definition.

Télécharger la présentation

Designing user interfaces using: Simple views

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. Designing user interfaces using: Simple views Designing user interfaces using: Simple views

  2. Views • Basic views • TextView • EditText • Button • ImageButton • CheckBox • ToggleButton • RadioButton • RadioGroup • Spinner • Pickers • TimePicker • DatePicker • Normally added to DialogFragment • Lists • ListView • ListActivity • ListFragment Designing user interfaces using: Simple views

  3. View definition • Views a usually defined in an XML file • Declarative • Example: res/layout/main.xml • Always in the folder res/layout • Each activity typically has one (or more) layout XML files. • Views can be defined in the Activity • Programmatically • This is not the usual way • Useful if you want a dynamic number of Views • Example: Quiz game where each question has a different number of possible answers • More on this later … Designing user interfaces using: Simple views

  4. Writing the view definition XML file • The layout XML file can be written in two ways • Pure XML • Graphical drag-and-drop GUI builder • The two ways can mixed Designing user interfaces using: Simple views

  5. View configuration • Some configuration can be done in the layout XML file • Width, height, etc. • Some configuration must be done in the Activity Java class • Programming event handlers • OnSomethingClicked(View …) etc. • Loading data into advanced views like lists Designing user interfaces using: Simple views

  6. Event handlers:Android vs. Windows forms Android Windows event handlers, etc. Every GUI component can have any number of event handlers of a certain type Usually 0 or 1, though Syntax Obj.event += eventHandler Observer design pattern Event handlers listen for changes in the GUI component Adding / removing listeners at runtime • Every GUI component has ONE event handler of a certain type • Strategy design pattern • GUI component calls the event handler to handle the event • Changing strategy at runtime Designing user interfaces using: Simple views

  7. Registering events for a view • Buttons etc. Can register event handlers • btn.setOnClickListener(btnListener); • Often using anonymous inner classes btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // do something } }); • Examples: ClickEventHandling project Android user interfaces using layouts

  8. Listening for User Interface notifications • When you press a key the view in focus will try to handle the event • Example: EditText handles left + right arrows, but not up + down arrows • Unhandled events are passed to the Activity • public booleanonKey(…) • Returned boolean value • True: The event handling has finished • False: The event handling has not finished • Example: ClickEventHandling Android user interfaces using layouts

More Related