Fragment 中使用 getLayoutInflater() 的问题
生活随笔
收集整理的這篇文章主要介紹了
Fragment 中使用 getLayoutInflater() 的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題:
我想在一個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.csdn.net/yuxin1100/article/details/51598133
總結
以上是生活随笔為你收集整理的Fragment 中使用 getLayoutInflater() 的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 精装修多少钱一平米啊?
- 下一篇: Manifest merger fail