Adapter to Fragment

 

1). Adapter (switch & send data)



//move adapter to fragment...
ProductListFragment productListFragment = new ProductListFragment();
((MainActivity) cn).getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_conteiner, productListFragment, "ProductListFragment")
.addToBackStack(null)
.commit();

//data passing...
Bundle bundle = new Bundle();
bundle.putString("KEY_CAT_TITLE", model.getTitle());
productListFragment.setArguments(bundle);


2). Fragment (get data)


if (getArguments() != null) {
    categoryTitle = getArguments().getString("KEY_CAT_TITLE");
} else {
//null data
}