我正在向ListFragment添加标题,但标题不会出现.我尝试添加onCreate和onStart,但我已经设置了我的适配器.我在这里找到这个
Best place to addHeaderView in ListFragment,但它无效.
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) { View v = getActivity().getLayoutInflater().inflate(R.layout.header,null); container.addView(v,0); rla = new RowListAdapter(getActivity().getLayoutInflater(),R.layout.itemlayout,rl); setListAdapter(rla); return super.onCreateView(inflater,container,savedInstanceState); } @Override public void onStart() { super.onStart(); getListView().setBackgroundResource(R.color.tostadoclaro); getListView() .setDivider(getResources().getDrawable(R.drawable.divider)); getListView().setDividerHeight(4); }
解!!!
@Override public void onActivityCreated(Bundle savedInstanceState) { View v = getActivity().getLayoutInflater().inflate(R.layout.header,null); this.getListView().addHeaderView(v); rla = new RowListAdapter(getActivity().getLayoutInflater(),rl); setListAdapter(rla); super.onActivityCreated(savedInstanceState); } public View onCreateView(LayoutInflater inflater,Bundle savedInstanceState){// Empty. Use original.}@H_403_8@