我试图从结果中获取name属性。到处看,无法弄清楚。当我登录时,我得到了这个:
[Person {id = 0,name =' Jonathon',age = 21}]
如何仅访问名称,而不是完整结果?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Realm realm = Realm.getDefaultInstance();
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Person person = realm.createObject(Person.class);
person.setName("Jonathon");
person.setAge(21);
}
});
RealmQuery<Person> query = realm.where(Person.class).equalTo("name", "Jonathon");
RealmResults<Person> result = query.findAll();
Log.d("Result", result.toString());
}
答案 0 :(得分:1)
RealmQuery<Person> query = realm.where(Person.class).equalTo("name", "Jonathon");
RealmResults<Person> result = query.findAll();
Person person = result.get(0);
Log.d("Result", person.getName());
答案 1 :(得分:0)
您的查询似乎运行正常。
reduce