我在ListView中添加一个可绘制的图像作为标题。我已经实现了如下的情况下的活动。
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;
}
}
在这件事上,我犯了个错误”
类型片段中的getLayoutFlater(bundle)方法不是
适用于参数()
“排队
View header = (View)getLayoutInflater().inflate(R.layout.header, null);
如何解决此错误?
谢谢
最佳答案
改变
View header = (View)getLayoutInflater().inflate(R.layout.header, null);
具有
View header = inflater.inflate(R.layout.header, null);
onCreatView
的第一个参数是aLayoutInflater