ce.Apparently 方法不是静态的
ce.Apparently the method is not static
我是java的新手,android.The方法getContext()
是直接调用的,没有被Viewclass的实例引用。显然,该方法 不是静态的 。怎么可能调用非静态方法 directly.What 我在这里失踪了吗?在下面添加了我的代码(疑问在最后一行)。
谢谢。
package in.shopperstreet.honeywell;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
public class CustomAdapter extends ArrayAdapter<String> {
public CustomAdapter(Context context, String[] books) {
super(context,R.layout.activity_main2,books);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater lif = LayoutInflater.from(getContext());
....
使用 getLayoutInflater()
,调用托管此适配器的 activity,超过 LayoutInflater.from()
。
public class CustomAdapter extends ArrayAdapter<String> {
final private LayoutInflater li;
public CustomAdapter(Activity host, String[] books) {
super(host,R.layout.activity_main2,books);
li=host.getLayoutInflater();
}
// other code goes here
}
getContext
方法属于 ArrayAdapter
。来自文档
Returns the context associated with this array adapter. The context is used to create views from the resource passed to the constructor.
我是java的新手,android.The方法getContext()
是直接调用的,没有被Viewclass的实例引用。显然,该方法 不是静态的 。怎么可能调用非静态方法 directly.What 我在这里失踪了吗?在下面添加了我的代码(疑问在最后一行)。
谢谢。
package in.shopperstreet.honeywell;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
public class CustomAdapter extends ArrayAdapter<String> {
public CustomAdapter(Context context, String[] books) {
super(context,R.layout.activity_main2,books);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater lif = LayoutInflater.from(getContext());
....
使用 getLayoutInflater()
,调用托管此适配器的 activity,超过 LayoutInflater.from()
。
public class CustomAdapter extends ArrayAdapter<String> {
final private LayoutInflater li;
public CustomAdapter(Activity host, String[] books) {
super(host,R.layout.activity_main2,books);
li=host.getLayoutInflater();
}
// other code goes here
}
getContext
方法属于 ArrayAdapter
。来自文档
Returns the context associated with this array adapter. The context is used to create views from the resource passed to the constructor.