Presentation is loading. Please wait.

Presentation is loading. Please wait.

Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.

Similar presentations


Presentation on theme: "Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton."— Presentation transcript:

1 Designing user interfaces using: Simple views 1

2 Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton – RadioGroup – Spinner Pickers – TimePicker – DatePicker Lists – ListView – ListActivity – ListFragment 2 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 … 3 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 4

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

6 Event handlers: Android vs. Windows forms Android 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 C# and Java event handlers, etc. Every GUI component can have any number of event handlers of a certain type – Usually 0 or 1, though Syntax C# – Obj.event += eventHandler Observer design pattern – Event handlers listen for changes in the GUI component – Adding / removing listeners at runtime 6 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 layouts7

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 boolean onKey(…) – Returned boolean value True: The event handling has finished False: The event handling has not finished Example: ClickEventHandling Android user interfaces using layouts8


Download ppt "Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton."

Similar presentations


Ads by Google