Android Programming Lecture 6 List View and Custom View
Android Programming Lecture 6 List View and Custom View
List View Android provides the view "List View"which is capable of displaying a scrollable list of items. Lists are one of the most common designs in mobile apps 11:09 420PM o oScrollable = Someone Like You o Selectable Space Bound 中。么手国四8甲+0 o Programmable to Stranger In Moscow ★★★★★2651 88 bring up the next ove The Way You Lie Tobias Fanke sn由Ckt )340. Activity (screen) wa明Mere Kh明 ★★★★92 946 All My Days 780 Life For Rent
List View • Android provides the view "List View" which is capable of displaying a scrollable list of items. • Lists are one of the most common designs in mobile apps 2 o Scrollable o Selectable o Programmable to bring up the next Activity (screen)
/。1第 Create the List ■Lsisplay Android iPhone windowsMobile Blackberry public class MainActivity extends ListActivity{ webos public void onCreate(Bundle savedInstanceState){ Ubuntu super.onCreate(savedInstanceState); windows7 Max OS X "List Activity"extends "Activity"and provides simplified handling of lists 3
3 public class MainActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // do not call the method setContentView(), as the List Activity has its default layout with a list view embedded // Step 1: Create the data String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; // Step 2: Create an Adapter object to convert data to list row ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values); // Step 3: Load the adapter to list view setListAdapter(adapter); } Create the List "List Activity" extends "Activity" and provides simplified handling of lists
Create the List ■ListDisplay Android iPhone WindowsMobile Blackberry public class MainActivity extends ListActivity{ webos public void onCreate(Bundle savedInstancestate){ Ubuntu super.onCreate(savedInstanceState); windows7 /do not call the method setContentview(),as the Max OS X List Activity has its default layout with a list view embedded /Step 1:Create the data String[]values new String[]{"Android","iPhone", "WindowsMobile","Blackberry","Webos","Ubuntu","Windows7","Max OS x", "Linux'","0s/2"; /Step 2:Create an Adapter object to convert data to list row ArrayAdapter<String>adapter new ArrayAdapter<string>(this, android.R.layout.simple list item 1,values); /Step 3:Load the adapter to list view setListAdapter(adapter);
4 public class MainActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // do not call the method setContentView(), as the List Activity has its default layout with a list view embedded // Step 1: Create the data String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; // Step 2: Create an Adapter object to convert data to list row ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values); // Step 3: Load the adapter to list view setListAdapter(adapter); } Create the List
Adapter:Man in the middle Data source Adapter ListView Cursor ArrayList ArrayAdapter:use TextView to represent the list items SimpleCursorAdapter:used with SQLite databases and content providers by converting cursor rows to list items 女
Adapter: Man in the middle 5 • ArrayAdapter: use TextView to represent the list items • SimpleCursorAdapter: used with SQLite databases and content providers by converting cursor rows to list items