我可以使用適配器在我的主要活動中打印學校名稱,如下面的代碼。如何在getView中列出活動中的領域列表?
我的問題是,如果我點擊學校名稱並想在另一個學生活動中列出學生姓名,我如何列出RealmList<Student> Students
的學生姓名,以及如何指定學生在學生適配器中的位置?
public class SchoolAdapter extends RealmBaseAdapter<School> implements ListAdapter {
private static class ViewHolder {
TextView school;
}
public SchoolAdapter(Context context, int resId, RealmResults<School> realmResults, boolean automaticUpdate) {
super(context, realmResults, automaticUpdate);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
viewHolder = new ViewHolder();
viewHolder.school = (TextView) convertView.findViewById(android.R.id.text1);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
School item = realmResults.get(position);
viewHolder.school.setText(item.getSchoolName());
return convertView;
}
public RealmResults<School> getRealmResults() {
return realmResults;
}
}
public class School extends RealmObject {
@Required
private String SchoolID;
private String SchoolName;
private RealmList<Student> Students;
//...getters/setters
}
public class Student extends RealmObject {
@Required
private String StudentID;
private String StudentName;
//...getters/setters
}