0
我有一個GridLayoutManager視圖回收站連接。默認情況下,它將顯示ONE COLUMN,如果用戶點擊按鈕,它將顯示在兩列中。如何改變GridLayoutManager列動態
adapter = new ProductAdapter(getActivity(), productList);
gridLayoutManager = new GridLayoutManager(getActivity(), 1);
setLayoutManager(true);
下面
是函數,其中我改變列
private void setLayoutManager(boolean isList) {
if (isList) {
adapter.VIEW_TYPE = 0 ;
gridLayoutManager.setSpanCount(1);
//product_recycler_view.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
product_recycler_view.setLayoutManager(gridLayoutManager);
} else {
adapter.VIEW_TYPE = 1 ;
gridLayoutManager.setSpanCount(2);
product_recycler_view.setLayoutManager(gridLayoutManager);
}
product_recycler_view.setAdapter(adapter);
adapter.notifyDataSetChanged();
// product_recycler_view.notify();
// product_recycler_view.notifyAll();
System.out.println("clicked isList "+ isList);
}