[Android] Using Selection Widgets

1,091 views

Published on

1. Introducing Adapters
1.1 Adapters
1.2 Using ArrayAdapter
1.3 Using ArrayAdapter (cont.)
1.4 Example 3.1
1.5 Custom ArrayAdapter
2. Using Selection Widgets
2.1 ListView
2.2 ListView (cont.)
2.3 Example 3.2
2.4 GridView
2.5 GridView (cont.)
2.6 Example 3.3
2.7 Spinners
2.8 Spinners (cont.)
3. Exercise 3

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,091
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

[Android] Using Selection Widgets

  1. 1. Android Programming Lesson 3Using Selection Widgets NGUYEN The Linh
  2. 2. Android ProgrammingContents 1 Introducing Adapters 2 Using Selection Widgets 3 Exercise 3 2
  3. 3. Android ProgrammingUsing Selection Widgets Introducing Adapters 3
  4. 4. Android ProgrammingIntroducing Adapters Adapters are bridging classes that bind data to user- interface Views. Using ArrayAdapter  The ArrayAdapter is a generic class that binds AdapterViews to an array of objects.  By default, the ArrayAdapter binds the toString() value of each object to a TextView control defined within a layout.  To apply an Adapter to an AdapterView-derived class, you call the View’s setAdapter() method, passing in an Adapter instance, as shown in the snippet below: 4
  5. 5. Android ProgrammingIntroducing Adapters Using ArrayAdapter (cont.) 5
  6. 6. Android ProgrammingIntroducing Adapters Example 3.1  Using Basic ArrayAdapter  Example 3.1 project • MainActivity.java • activity_main.xml 6
  7. 7. Android ProgrammingIntroducing Adapters Custom ArrayAdapter  You can subclass ArrayAdapter and override getView() to “roll your own” views: 7
  8. 8. Android ProgrammingUsing Selection Widgets Using Selection Widgets 8
  9. 9. Android ProgrammingUsing Selection Widgets ListView  The classic Android ListView is a plain list of text.  However, you can have a list whose rows are made up of icons, or icons and text, or check-boxes and text, or whatever you want.  Update Example 3.1 project 9
  10. 10. Android ProgrammingUsing Selection Widgets 10
  11. 11. Android ProgrammingUsing Selection Widgets ListView (cont.)  Custom ArrayAdapter for binding more data  See Example 3.2 11
  12. 12. Android ProgrammingUsing Selection Widgets Example 3.2  Custom ArrayAdapter  Example 3.2 project • MainActivity.java • Person.java • MyArrayAdapter.java • activity_main.xml • list_item.xml 12
  13. 13. Android ProgrammingUsing Selection Widgets 13
  14. 14. Android ProgrammingUsing Selection Widgets Better. Stronger. Faster. Using convert View 14
  15. 15. Android ProgrammingUsing Selection Widgets GridView  As the name suggests, GridView gives you a two-dimensional grid of items to choose from.  You have moderate control over the number and size of the columns; the number of rows is dynamically determined based on the number of items the supplied adapter says are available for viewing. 15
  16. 16. Android ProgrammingUsing Selection Widgets GridView (cont.)  Properties • android:numColumns spells out how many columns there are, or, if you supply a value of auto_fit, Android will compute the number of columns based on available space and the following properties. • android:verticalSpacing and its counterpart android:horizontalSpacing indicate how much whitespace there should be between items in the grid. • android:columnWidth indicates how many pixels wide each column should be. 16
  17. 17. Android ProgrammingUsing Selection Widgets GridView (cont.)  Properties (cont.) • android:stretchMode; this should be columnWidth to have the columns take up available space or spacingWidth to have the whitespace between columns absorb extra space.  Otherwise, the GridView works much like any other selection widget—use setAdapter() to provide the data and child views. 17
  18. 18. Android ProgrammingUsing Selection Widgets Example 3.3  GridView  Example 3.3 project • MainActivity.java • MyArrayAdapter.java • activity_main.xml • gridview_item.xml 18
  19. 19. Android ProgrammingUsing Selection Widgets Spinners  Spinners provide a quick way to select one value from a set. 19
  20. 20. Android ProgrammingUsing Selection Widgets Spinners (cont.)  The choices you provide for the spinner can come from any source, but must be provided through an SpinnerAdapter, such as an ArrayAdapter 20
  21. 21. Android ProgrammingExercise 3 21
  22. 22. Android Programming

×