我在列表视图中添加一个可绘制图像作为标题。如果有活动,我已按如下方式实施。
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.header, null);
listView1.addHeaderView(header);
但是,现在我正在尝试在这样的 viewpager 片段中实现相同的功能
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ShowFrag1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v=inflater.inflate(R.layout.frag1, container,false);
ListView lv1=(ListView) v.findViewById(R.id.listView1);
Level weather_data[] = new Level[]
{
new Level(R.drawable.s1, "L1", R.drawable.p),
new Level(R.drawable.s2, "L2",R.drawable.p),
new Level(R.drawable.s3, "L3",R.drawable.p),
new Level(R.drawable.s4, "L4",R.drawable.p),
new Level(R.drawable.s6, "L5",R.drawable.p)
};
LevelAdapter adapter = new LevelAdapter(getActivity(),
R.layout.list_item, weather_data);
View header = (View)getLayoutInflater().inflate(R.layout.header, null);
lv1.addHeaderView(header);
lv1.setAdapter(adapter);
return v;
}
}
现在在这里,我收到一个错误“
Fragment 类型中的 getLayoutInflater(Bundle) 方法不适用于 arguments()
“在行中
View header = (View)getLayoutInflater().inflate(R.layout.header, null);
我该如何解决这个错误?谢谢