添加标题到fragmentlist android

前端之家收集整理的这篇文章主要介绍了添加标题到fragmentlist android前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在向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@

解决方法

不要将视图添加到容器中.使用addHeaderView(v). @H_403_8@ @H_403_8@

猜你在找的Android相关文章