gpt4 book ai didi

android - fragment 中的 getLayoutInflater()

转载 作者:IT王子 更新时间:2023-10-28 23:49:24 28 4
gpt4 key购买 nike

我试图在 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);

关于android - fragment 中的 getLayoutInflater(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26368178/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com