在我的主要活动中,我喜欢将结果值从另一个类传递给处理适配器类。然而,它撞毁了我。
语法正确,可以编译,但会崩溃 我的问题是,将SettingPosition从Setting类传递给学校类的School适配器是什么样的呢?
主要活动
public class MainActivity extends AppCompatActivity {
....
Setting setting = realm.where(Setting.class).findFirst();
//radioPosition is from Setting Class
Integer radioPosition = setting.getPosition();
RealmResults<School> schools = realm.where(School.class).findAll();
//schools is from School Class
final SchoolAdapter adapter = new SchoolAdapter(this, R.id.schools_list, schools, Integer radioPosition, true);
....
}
学校适配器:
public class SchoolAdapter extends RealmBaseAdapter<School> implements ListAdapter {
....
public SchoolAdapter(Context context, int resId, RealmResults<School> realmResults, Integer radioPosition, 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();
}
.....