2013-07-04 137 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類的對象。