Head Fisrt Android Development读书笔记(6)Lists and Adapters
来源:互联网 发布:软件著作 编辑:程序博客网 时间:2024/05/17 09:06
ListView = ScrollView[ ViewGroup[A View for Each Row] ]
Adapter
an interface whose implementations provide data and the display of that data used by the ListView.
public class TimeTrackerAdapter extends BaseAdapter {
...
}
View getView(int index, View view, ViewGroup parent)
return the view used to display data in the ListView
define time_list_item.xml in /res/layout/
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/time_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="18dp" android:paddingBottom="5dp" /> <TextView android:id="@+id/note_view" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="12dp" /></LinearLayout>
Steps to complete getView
1.Instantiate the View
null input view--> initialize
not null --> repopulating
2.Retrieve the data
3.Set values on the view
R.layout.time_list_item
public View getView(int i, View view, ViewGroup viewGroup) { if (view == null) { LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext()); view = inflater.inflate(R.layout.time_list_item, viewGroup, false); } TimeRecord timeRecord = records.get(i); TextView timeTextView = (TextView) view.findViewById(R.id.time_view); timeTextView.setText(timeRecord.getTime()); TextView noteTextView = (TextView) view.findViewById(R.id.note_view); noteTextView.setText(timeRecord.getNote()); return view; }
connect listview with adapter
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView listView = (ListView) findViewById(R.id.times_list); TimeTrackerAdapter timeTrackerAdapter = new TimeTrackerAdapter(); listView.setAdapter(timeTrackerAdapter); }
- Head Fisrt Android Development读书笔记(6)Lists and Adapters
- Head Fisrt Android Development读书笔记(1)Adding Behavior
- Head Fisrt Android Development读书笔记(2)Working with Feeds
- Head Fisrt Android Development读书笔记(4)Multiple Device Support
- Head Fisrt Android Development读书笔记(7)Multi Screep Apps
- Head Fisrt Android Development读书笔记(7)Database Persistent
- Head Fisrt Android Development读书笔记(3)When things take time
- AndroidAnnotations——Adapters and lists 适配器和列表
- AndroidAnnotations——Adapters and lists 适配器和列表
- Head First Android Development-笔记
- Android Journey: <<Head First Android Development>>
- fisrt
- 技术书籍也香艳——《Head Fisrt 设计模式》
- Understanding Video and Graphics Adapters
- Head First Software Development
- learn iphone and ipad cocos2d Game Development读书笔记
- 读书笔记:3D Math Primer for Graphics and Game Development
- 【STL】适配器(adapters)
- Android在对话框中实现登录与注册
- Ubuntu常用软件源小结
- 用C#创建Windows服务(Windows Services)
- GDB使用
- 很全的SQL注入语句,有SQL漏洞的都可以拿下
- Head Fisrt Android Development读书笔记(6)Lists and Adapters
- 数据挖掘与OLAP
- VS2010无法显示资源视图和类视图的解决办法
- linux 根据 access.log 生成压力测试脚本 监控Mysql JAVA 系统状态
- svn忽略文件或目录
- 中国巴西等国敦促美尽快批准IMF改革方案-中国-美国-IMF
- fork与vfork的区别
- ubuntu安装phpmyadmin
- 快速排序