ListFragment does not accept my layout

前端 未结 10 1388
情歌与酒
情歌与酒 2020-12-01 02:09

According to this link: ListFragment android developers

I want to set my custom layout for list, but it makes exceptions.

Here is the code:

p         


        
10条回答
  •  甜味超标
    2020-12-01 02:57

    This might be easier: Create your layout as you would normally but don't add the list/empty/loading stuff. Then in your listfragment's onCreateView:

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = super.onCreateView(inflater, container, savedInstanceState);
        ViewGroup parent = (ViewGroup) inflater.inflate(R.layout.mylayout, container, false);
        parent.addView(v, 0);
        return parent;
    }
    

    Now you can use setListShown...

提交回复
热议问题