Android 无法识别getSystemService()方法

Android 无法识别getSystemService()方法,android,listadapter,Android,Listadapter,LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE) 我使用的是getSystemService(),但出现了“类型CustomAdapter的方法getSystemService(String)未定义”错误 使用什么来代替getSystemService或任何其他解决方案?您可以这样制作适配器 LayoutInflater vi = (LayoutInflater) You

LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT\u INFLATER\u SERVICE)

我使用的是getSystemService(),但出现了“类型CustomAdapter的方法getSystemService(String)未定义”错误


使用什么来代替getSystemService或任何其他解决方案?

您可以这样制作适配器

LayoutInflater vi = (LayoutInflater) YourEnclosingActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
public CustomAdapter(YourActivtyName context) {

    LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
试试这个:

LayoutInflater vi = (LayoutInflater)YourClassName.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
或:


其中,
context
context
类的对象。

请参见,getSystemService方法是一种上下文方法。因此,在CustomAdapter中,您应该以某种方式获得活动的上下文。如果适配器位于不同的文件中或是嵌套的静态类,请尝试在构造函数中传递它。
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);