2013-07-04 125 views
0

LayoutInflater vi =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);getSystemService()方法不被识别

我使用getSystemService(),但是,我取“的方法getSystemService(字符串)是未定义的类型CustomAdapter”错误

改用getSystemService或任何其他解决方案的是什么?

回答

0
LayoutInflater vi = (LayoutInflater) YourEnclosingActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
+0

不幸的是,它不起作用 – erdemgc

+0

请参阅getSystemService方法是Context的方法。所以,在您的CustomAdapter中,您应该以某种方式获取您的Activity的上下文。如果您的适配器位于不同的文件中,或者是嵌套的静态类,请尝试将它传递给构造函数。 –

1

,你可以作出这样

public CustomAdapter(YourActivtyName context) { 

    LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 
0

适配器试试这个

LayoutInflater VI =(LayoutInflater)YourClassName.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LayoutInflater VI =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

其中上下文是Context类的对象。