西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 6 List View and Custom View

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 adapter = new ArrayAdapter(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 ArrayAdapteradapter new ArrayAdapter(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 adapter = new ArrayAdapter(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

ArrayAdapteradapter new ArrayAdapter(this, android.R.layout.simplelist item_1,values); 可坐 零145 /6403 B□G1:27AM ndroldListVlew CustomTwoLineListActivity Interiace January Red hello 7 the color red February Green world March Blue the color blue musart April May June July simple_list item1 simple list_item 2 simple_list_item_single_choice 6
6 simple_list_item_1 simple_list_item_2 simple_list_item_single_choice ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, values);

41108 ■ListDisplay User Interaction in List View Android iPhone WindowsMobile Blackberry User setListAdapter()to inflate Webos the list view using the adapter Ubuntu Windows7 If the user select in the list a list entry Max OSX the method onListItemclick() will be called.This method allows to access the selected element. @Override protected void onListItemClick(ListView 1,View v,int position,long id){ super.onListItemClick(1,v,position,id); /Callback function when an item in the list is clicked /ListView 1:The ListView where the click happened /View v:The view that was clicked within the ListView /int position:The position of the view in the list /long id:The row id of the item that was clicked
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // Callback function when an item in the list is clicked // ListView l: The ListView where the click happened // View v: The view that was clicked within the ListView // int position: The position of the view in the list // long id: The row id of the item that was clicked } User Interaction in List View • User setListAdapter() to inflate the list view using the adapter • If the user select in the list a list entry the method onListItemClick() will be called. This method allows to access the selected element. 7

"4110词 Android iPhone B副ac0ermy public class MainActivity extends ListActivity Ubuntu public void onCreate(Bundle savedInstanceState){ Windows7 Max O5 X super.onCreate(savedInstanceState); String[]values=new String[]{"Android","iPhone","Windows Mobile", "Blackberry","WebOS","Ubuntu","Windows 7","Max OS X", "Linux","Windows 8"}; ArrayAdapteradapter new ArrayAdapter(this, android.R.layout.simple list item 1,R.id.label,values); setListAdapter (adapter); @Override protected void onListItemClick(ListView 1,View v,int position,long id){ super.onListItemclick(1,v,position,id); String item=(String)getListAdapter().getItem(position); Toast.makeText(this,item +selected with position"+position +and id"+id, Toast.LENGTH LONG)show () 8
8 public class MainActivity extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] values = new String[] { "Android", "iPhone", "Windows Mobile", "Blackberry", "WebOS", "Ubuntu", "Windows 7", "Max OS X", "Linux", "Windows 8" }; ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, R.id.label, values); setListAdapter(adapter); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); String item = (String) getListAdapter().getItem(position); Toast.makeText(this, item + " selected with position " + position + " and id " + id, Toast.LENGTH_LONG).show(); } }

Apply Your Own Layout 811:08 List View ■ListDisplay Android This is Tom's list view iPhone Android WindowsMobile iPhone WindowsMobile Blackberry Blackberry Webos Webos Ubuntu Ubuntu Windows7 Windows7 Max OS X Max0S× Using default layout in Using your own ListActivity layout file 9
Apply Your Own Layout Using default layout in ListActivity 9 Using your own layout file

Customize List View "@android:id/list"which is the In activity java file,still use the method setContentview() protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentview (R.layout.activity main); 10
Customize List View • In case you don't want to use one of the pre-defined layouts your own layout must have an element with the id "@android:id/list" which is the ListView • In activity java file, still use the method setContentView() 10 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 5 Intent.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 4 Activity, Intent and UI.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 3 File structure and Layout.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 2 Introduction to Java and Object Oriented Programming.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 1 Introduction to Network Computing(主讲:栾浩).pptx
- 《算法基础》课程教学资源(学习笔记)算法基础 课堂笔记.pdf
- 长沙理工大学:《微机原理与接口技术》课程教学资源(大纲教案)微机原理与应用授课教案(负责人:叶青,打印版).pdf
- 同济大学:《逻辑网络》课程电子教案(PPT课件)数字设计中的基本电路 Introduction to the circuits in digital design.ppt
- 同济大学:《逻辑网络》课程电子教案(PPT课件)异步时序电路分析与设计 Introduction to asynchronous circuits design.ppt
- 同济大学:《逻辑网络》课程电子教案(PPT课件)寄存器与计数器 register and counters.ppt
- 同济大学:《逻辑网络》课程电子教案(PPT课件)同步时序电路设计中的问题 Advanced design issue.ppt
- 同济大学:《逻辑网络》课程教学资源(试卷习题)考试样卷.doc
- 同济大学:《逻辑网络》课程教学资源(教学大纲)逻辑网络(英文)Logic networks.doc
- 同济大学:《逻辑网络》课程教学资源(教学大纲)逻辑网络(中文,负责人:周俊鹤).doc
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第六章 查找.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第五章 图.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第三章 栈和队列.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第二章 线性表.ppt
- 北京化工大学:《数据结构》课程PPT教学课件(C语言描述)第一章 绪论(负责人:侯虹).ppt
- 北京化工大学:《大学计算机基础》课程电子教案(PPT教学课件)第7章 多媒体技术基础.ppt
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 7 Data Persistence.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 8 Multi-threading.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 9 Service and Broadcast Receiver.pptx
- 西安电子科技大学:《网络计算》课程PPT教学课件(Android Programming)Lecture 10 Multimedia.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 01 Soft Testing - Fundamentals of Testing.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 02 Testing throughout the Software Lifecycle.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 03 Static Techniques.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 04 Test Design Techniques.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 05 Test Management.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)Chapter 06 Tool Support for Testing.pptx
- 同济大学:《软件测试》课程电子教案(PPT课件)How To Do High Quality Research, Write Acceptable Papers, and Make Effective Presentations?.ppt
- 《软件测试》课程电子教案(参考资料)Standard glossary of terms used in Software Testing(Version 2.0).pdf
- 《软件测试》课程电子教案(参考资料)Certified Tester Foundation Level Syllabus Released(Version 2011).pdf
- 《软件测试》课程电子教案(参考资料)Certified Tester Foundation Level Syllabus Released(Version 2011).pdf
- 河南科技大学:信息工程学院教育技术学专业本科课程教学大纲(汇编).pdf
- 吉林大学:《人工智能》课程电子教案(PPT课件)第一章 绪论 Artificial Intelligence(AI).ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第七章 机器学习.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第三章 知识与知识表示.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第二章 人工智能的数学基础.ppt
- 吉林大学:《人工智能》课程电子教案(PPT课件)第五章 搜索策略.ppt