Java Code Examples for android.support.v7.widget.LinearLayoutManager#setRecycleChildrenOnDetach()

The following examples show how to use android.support.v7.widget.LinearLayoutManager#setRecycleChildrenOnDetach() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecyclerViewActivity.java    From CommonAdapter with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mRecyclerView = new RecyclerView(this);
    LayoutUtil.setContentView(this, mRecyclerView);

    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    layoutManager.setRecycleChildrenOnDetach(true);
    mRecyclerView.setLayoutManager(layoutManager);

    // 放一个默认空数据
    mRecyclerView.setAdapter(getAdapter(null));

    // 现在得到数据
    final List<DemoModel> data = DataManager.loadData(getBaseContext());
    ((IAdapter<DemoModel>) mRecyclerView.getAdapter()).setData(data); // 设置新的数据
    mRecyclerView.getAdapter().notifyDataSetChanged(); // 通知数据刷新

    loadNewData(data);
}
 
Example 2
Source File: DisplayListFragment.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void configureRecyclerView(RecyclerView recyclerView) {
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    linearLayoutManager.setRecycleChildrenOnDetach(false);
    linearLayoutManager.setSmoothScrollbarEnabled(false);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setHorizontalScrollBarEnabled(false);
    recyclerView.setVerticalScrollBarEnabled(true);
}