[英]Passing Realm variable from other class to getView in the adapter
在我的主要活動中,我喜歡將結果值從另一個類傳遞到適配器中的getview。
我可以將變量radioPosition傳遞給適配器,但不能在getView()中使用它;
我的問題是如何將我的Setting類中的領域變量傳遞給School適配器中的getview()
主要活動
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();
}
.....
private int mRadioPosition;
public SchoolAdapter(Context context, int resId, RealmResults<School> realmResults, Integer radioPosition, boolean automaticUpdate) {
super(context, realmResults, automaticUpdate);
mRadioPosition = radioPosition;
}
在getView方法中使用mRadioPosition
。 如果我誤解了您的問題,請告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.