现在,我想能有一个人得到(int i)以从光标适配器方法。 ..
这似乎是一个奇怪的要求。我会将Cursor本身(或从CursorAdapter的getItem()
返回的游标)转换为我的Activity中的常规方法。 但这里的基本步骤来创建一个Person get()
方法。
创建Person类:
public class Person {
long id;
String firstName;
String surname;
}
而且在自定义的CursorAdapter简单地使用这样的方法:
public Person get(int position) {
Cursor cursor = getCursor();
Person person;
if(cursor.moveToPosition(position)) {
person = new Person();
person.id = cursor.getLong(cursor.getColumnIndex("_id"));
person.firstName = cursor.getString(cursor.getColumnIndex("firstName"));
person.surname = cursor.getString(cursor.getColumnIndex("surname"));
results.add(person);
}
return person;
}
来源
2012-08-29 16:42:01
Sam
这是正确的并且应该接受的答案 – user123321
棒极了!从未知道。我的生活节省了几个小时! – barmaley