片段中的 getLayoutInflater() [英] getLayoutInflater() in fragment
本文介绍了片段中的 getLayoutInflater()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在 Fragment
上的 ListView
中显示我的搜索结果,但它失败了:
LayoutInflater inflater = getLayoutInflater();
<块引用>
Fragment 类型中的 getLayoutInflater(Bundle) 方法不是适用于参数 ()
这是我的代码:
public View getView(int position, View convertView, ViewGroup parent){LayoutInflater inflater = getLayoutInflater();查看行;row = inflater.inflate(R.layout.list_single, parent, false);TextView textview = (TextView) row.findViewById(R.id.TextView01);ImageView imageview = (ImageView) 行.findViewById(R.id.ImageView01);textview.setText(data_text[位置]);imageview.setImageResource(data_image[位置]);返回(行);}
我该如何解决这个问题?
解决方案
如果你在想要的片段
getActivity().getLayoutInflater();
或
LayoutInflater.from(getActivity());
你也可以
View.inflate();
或
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
I'm trying to show my results search in a ListView
on the Fragment
, but it fails on:
LayoutInflater inflater = getLayoutInflater();
The method getLayoutInflater(Bundle) in the type Fragment is not applicable for the arguments ()
This is my code:
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);
}
How can I fix this?
解决方案
if you are in a fragment you want
getActivity().getLayoutInflater();
or
LayoutInflater.from(getActivity());
also you can do
View.inflate();
or
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
这篇关于片段中的 getLayoutInflater()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文