#android #android-arrayadapter
#Android #android-arrayadapter
Вопрос:
Я пытаюсь отделить реализацию ArrayAdapter от класса activity. До сих пор я перенес его в отдельный класс, но getSystemService() вызывает у меня проблемы.
Я пытался передать контекст в конструкторе следующим образом
public KontaktAdapter(Context context, int textViewResourceId, ArrayList<Kontakt> items) {
super(context, textViewResourceId, items);
this.context = context;
Но ни одна из следующих работ
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
РЕДАКТИРОВАТЬ: наконец-то это, похоже, работает для меня сейчас
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Ответ №1:
Попробуйте
LayoutInflater vi = LayoutInflater.from(context);