问题:
我想在一个Fragment的ListView中显示我的搜索结果
但在这里报错:
LayoutInflater inflater = getLayoutInflater();
“The method getLayoutInflater(Bundle) in the type Fragment is not applicable for the arguments ()”
代码如下:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row;
row = inflater.inflate(R.layout.list_single, parent, false);
TextView textview = (TextView) row.findViewById(R.id.TextView01);
ImageView imageview = (ImageView) row.findViewById(R.id.ImageView01);
textview.setText(data_text[position]);
imageview.setImageResource(data_image[position]);
return (row);
}
如何解决?
解决方法:
如果是在一个 Fragment 中应该
getActivity().getLayoutInflater();
或者
LayoutInflater.from(getActivity());
也可以
View.inflate();
或者
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-------转载地址:http://blog.youkuaiyun.com/yuxin1100/article/details/51598133