2011-11-02 72 views
0

我尝试将ArrayAdapter的实现与Activity类分开。 到目前为止,我把它移动到单独的类,但getSystemService()导致我的问题。Android自己的ArrayAdapter实现

I`ve尝试在构造函数传递上下文这样

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); 

回答

0

试试

LayoutInflater vi = LayoutInflater.from(context);