ActiveAndroid的特点和优势
什么是ORM 框架:ORM (Object Relational Mapping)框架采用元数据来描述对象与关系映射细节。把对象持久化到数据库中。就是利用Java的反射机制把对象和数据库记录映射关联起来。很类似于Hibernate的对象关系映射(ORM)。
ActiveAndroid 的基本用法:
@Table(name = "Students")
public class Student extends Model {
@Column(name = "Name")
public String name;
@Column(name = "Age")
public Integer age;
}
<pre name="code" class="java">/**
* 增删改查学生基本信息
*
* @author Administrator
*
*/
public class MainActivity extends Activity {
private Button btn_add;
private ListView lv;
private StuAdapter adapter;
private ArrayList<Student> list = new ArrayList<Student>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
btn_add = (Button) this.findViewById(R.id.btn_add);
lv = (ListView) this.findViewById(R.id.lv);
adapter = new StuAdapter(this, list);
lv.setAdapter(adapter);
List<Student> stus = new Select().from(Student.class).execute();
for (int i = 0; i < stus.size(); i++) {
Student student = stus.get(i);
student.name = "HanMeiMei";
student.save();
}
list.addAll(stus);
for (int i = 0; i < 8; i++) {
Student stu = new Student();
stu.name = "Lilei" + i;
stu.age = 10 + i;
stu.save();
list.add(stu);
}
adapter.notifyDataSetChanged();
btn_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Student stu = new Student();
stu.name = "Lucy";
stu.age = 12;
stu.save();
list.add(stu);
adapter.notifyDataSetChanged();
}
});
}
}
需要demo者留言1719164924@qq.com