Android 5.0 - 將頁眉/頁腳添加到RecyclerView我花了一些時間試圖找出一種方法來添加一個標題RecyclerView,但沒有成功。這是我到目前為止所得到的:@Overrideprotected void onCreate(Bundle savedInstanceState){
...
layouManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layouManager);
LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
headerPlaceHolder = inflater.inflate(R.layout.view_header_holder_medium, null, false);
layouManager.addView(headerPlaceHolder, 0);
...}在LayoutManager似乎是處理的配置對象RecyclerView的項目。因為我無法找到任何addHeaderView(View view)方法,我決定去與LayoutManager的addView(View view, int position)方法,并增加我的頭鑒于第一位置,像一個頭。Aaand這是事情變得更加丑陋的地方:java.lang.NullPointerException: Attempt to read from field 'android.support.v7.widget.RecyclerView$ViewHolder android.support.v7.widget.RecyclerView$LayoutParams.mViewHolder' on a null object reference
at android.support.v7.widget.RecyclerView.getChildViewHolderInt(RecyclerView.java:2497)
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:4807)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:4803)
at com.mathieumaree.showz.fragments.CategoryFragment.setRecyclerView(CategoryFragment.java:231)
at com.mathieumaree.showz.fragments.CategoryFragment.access$200(CategoryFragment.java:47)
at com.mathieumaree.showz.fragments.CategoryFragment$2.success(CategoryFragment.java:201)在幾次NullPointerExceptions嘗試調(diào)用addView(View view)Activity創(chuàng)建的不同時刻(也嘗試在設(shè)置完一切后添加視圖,甚至是Adapter的數(shù)據(jù))后,我意識到我不知道這是否是正確的方法(并且它看起來不是)。PS:此外,一個可以處理GridLayoutManager除此之外的解決方案LinearLayoutManager將非常感謝!
- 3 回答
- 0 關(guān)注
- 1073 瀏覽
添加回答
舉報
0/150
提交
取消