基于FastDatabase的适配器
来源:互联网 发布:淘宝被禁言了怎么解除 编辑:程序博客网 时间:2024/06/06 01:43
fastLib库是一个Android平台通用库,能快速提高项目效率。fastlib库
fastLib中有一个FastDatabase用来简化对数据库操作
这次我带来基于FastDatabase的适配器,在批量取数据显示时很有帮助
假设我需要加载一个存储在数据库的通讯录列表,我可以这样写
通讯录中每条记录仅id,姓名和年龄
public class Person{ //指定主键,并且自动增长 @Database(keyPrimary = true,autoincrement = true) public int id; public int age; public String name;}
每条通讯录记录的布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:padding="10dp"> <TextView android:id="@+id/id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15sp" android:text="id"/> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="name"/> <TextView android:id="@+id/age" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="age"/></LinearLayout>
通讯录适配器,仅显示它的3个属性
/** * 通讯录适配器 */public class PersonDbAdapter extends DatabaseAdapter<Person>{ public PersonDbAdapter(Context context){ super(context,Person.class,R.layout.item); } @Override protected void binding(int position, Person data, OldViewHolder holder){ holder.setText(R.id.name,data.name); holder.setText(R.id.id,Integer.toString(data.id)); holder.setText(R.id.age,Integer.toString(data.age)); }}
主界面布局。我额外加了一个排序的按键
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/sort" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="正序"/> <com.fastlib.widget.RefreshLayout android:id="@+id/refresh" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent"/> </com.fastlib.widget.RefreshLayout></LinearLayout>
主界面代码
public class MainActivity extends FastActivity{ @Bind(R.id.refresh) Refreshable mRefresh; @Bind(R.id.list) ListView mList; PersonDbAdapter mAdapter; boolean isAsc=true; @Override protected void onCreate(@Nullable Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } @Bind(R.id.sort) public void commit(View v){ isAsc=!isAsc; ((TextView)v).setText(isAsc?"正序":"倒序"); mAdapter.setAsc(isAsc); mAdapter.refresh(); } private void init(){ mAdapter=new PersonDbAdapter(this); mList.setAdapter(mAdapter); mAdapter.setRefreshable(mRefresh); mRefresh.setRefreshCallback(new Refreshable.RefreshCallback(){ @Override public void startRefresh(){ mAdapter.refresh(); } }); }}
如有疑问,请在下方评论,我会尽可能及时回复
0 0
- 基于FastDatabase的适配器
- FastDatabase基础使用
- 基于对象适配器模式的分页组件
- 基于注解的映射器和适配器
- 第一次看基于osgi的适配器框架的设计
- Power基于 VIOS 的虚拟以太网适配器的工作原理
- 基于Hadoop的日志收集框架---Chukwa的源码分析(适配器、代理)
- android适配器之基于BaseAdapt自定义简单适配器
- C++ 下基于迭代器适配器和范型算法的排序
- tcc893x基于Linux内核的I2C总结(I2C基础、I2C适配器驱动分析)
- 【C++】STL常用容器总结之六:基于deque的顺序容器适配器
- 基于BaseAdapter扩展的服务器数据与本地视图绑定适配器
- 基于mpc体系架构的I2C体系结构(适配器与core层交互)
- 基于codeigniter框架写的网站日志系统适配器(支持写入本地文件、数据库、远程服务器)
- IIC适配器级别分析-基于s3c2410
- 基于Vector实现适配器stack(顺序栈)
- 适配器模式(Adapter)-----基于JAVA语言
- 基于List实现适配器queue(链式队列)
- 二当家的官网微信小程序源码实例解析
- FaceNet: A Unified Embedding for Face Recognition and Clustering 笔记
- java上传带旋转角度的图片旋转问题
- Android按钮的五种点击监听事件处理
- 使用adaboost+haar分类器检测车辆demo
- 基于FastDatabase的适配器
- python利用LSTM进行时间序列分析预测
- VS2015快捷键大全
- ubuntu 16.04 安装 Jenkins
- 互联网公司校招Java面试题总结及答案——美团
- 信用卡提额的10种方法
- vue-cli 安装
- socket编程
- android_72_写入短信