下面列出了android.support.v7.widget.StaggeredGridLayoutManager#VERTICAL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initRecycleView(){
final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
mRcvIndexContent.setLayoutManager(layoutManager);
mAdapter = new ViewListAdapter(this);
mAdapter.setIClickItem(this);
mRcvIndexContent.setAdapter(mAdapter);
mRcvIndexContent.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
boolean isBottom =
layoutManager.findLastCompletelyVisibleItemPositions(new int[2])[1]
>= mAdapter.getItemCount() - 4;
if (!mSwipeRefreshLayout.isRefreshing() && isBottom && mHasMoreData) {
showRefresh();
mPresenter.getDataMore();
}
}
});
}
@Override
public void initSubViews(View view) {
super.initSubViews(view);
staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
meiziAdapter = new FooterRecyclerAdapter<>(new MeiziAdapter());
recyclerView.setLayoutManager(staggeredGridLayoutManager);
recyclerView.setAdapter(meiziAdapter);
scrollListener = new BaseRecyclerOnScrollListener(staggeredGridLayoutManager) {
@Override
public void onLoadMore(int currentPage) {
mPresenter.requestMeizi(currentPage);
}
};
recyclerView.addOnScrollListener(scrollListener);
swipeRefreshLayout.setOnRefreshListener(this);
}
private void refreshRecyclerView(int column) {
MyAdapter myAdapter = new MyAdapter(MainActivity.this);
HeaderAndFooterRecyclerViewAdapter adapter = new HeaderAndFooterRecyclerViewAdapter(myAdapter);
recyclerView.setAdapter(adapter);
ExStaggeredGridLayoutManager staggeredGridLayoutManager = new ExStaggeredGridLayoutManager(column, StaggeredGridLayoutManager.VERTICAL);
staggeredGridLayoutManager.setSpanSizeLookup(new HeaderSpanSizeLookup((HeaderAndFooterRecyclerViewAdapter) recyclerView.getAdapter(), staggeredGridLayoutManager.getSpanCount()));
recyclerView.setLayoutManager(staggeredGridLayoutManager);
View headerView = LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_header, null);
View footerView = LayoutInflater.from(MainActivity.this).inflate(R.layout.layout_footer, null);
RecyclerViewUtils.setHeaderView(recyclerView, headerView);
RecyclerViewUtils.setFooterView(recyclerView, footerView);
}
private void initRecycler(ImageStreamAdapter adapter) {
final int columns = bottomSheet.getContext().getResources().getInteger(R.integer.belvedere_image_stream_column_count);
final StaggeredGridLayoutManager staggeredGridLayoutManager =
new StaggeredGridLayoutManager(columns, StaggeredGridLayoutManager.VERTICAL);
imageList.setLayoutManager(staggeredGridLayoutManager);
imageList.setHasFixedSize(true);
imageList.setDrawingCacheEnabled(true);
imageList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
final DefaultItemAnimator defaultItemAnimator = new DefaultItemAnimator();
defaultItemAnimator.setSupportsChangeAnimations(false);
imageList.setItemAnimator(defaultItemAnimator);
imageList.setAdapter(adapter);
}
/**
* 判断是否是最后一列
*/
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount) {// 如果是最后一列,则不需要绘制右边
return true;
}
}
}
return false;
}
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
return true;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
// StaggeredGridLayoutManager 且纵向滚动
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
childCount = childCount - childCount % spanCount;
// 如果是最后一行,则不需要绘制底部
if (pos >= childCount)
return true;
} else
// StaggeredGridLayoutManager 且横向滚动
{
// 如果是最后一行,则不需要绘制底部
if ((pos + 1) % spanCount == 0) {
return true;
}
}
}
return false;
}
@Override
protected ILayoutManager getLayoutManager() {
random = new Random().nextInt(3);
switch (random) {
case 0:
return new MyLinearLayoutManager(getContext());
case 1:
return new MyGridLayoutManager(getContext(), 3);
case 2:
return new MyStaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
}
return super.getLayoutManager();
}
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
int childCount) {
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
return true;
}
else if (layoutManager instanceof StaggeredGridLayoutManager) {
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
// StaggeredGridLayoutManager 且纵向滚动
if (orientation == StaggeredGridLayoutManager.VERTICAL) {
childCount = childCount - childCount % spanCount;
// 如果是最后一行,则不需要绘制底部
if (pos >= childCount)
return true;
}
else {
// 如果是最后一行,则不需要绘制底部
if ((pos + 1) % spanCount == 0) {
return true;
}
}
}
return false;
}
private void initView(){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
coordinatorLayout=(CoordinatorLayout)findViewById(R.id.behavior_demo_coordinatorLayout);
recyclerview=(RecyclerView)findViewById(R.id.behavior_demo_recycler);
mLayoutManager=new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerview.setLayoutManager(mLayoutManager);
swipeRefreshLayout=(SwipeRefreshLayout) findViewById(R.id.behavior_demo_swipe_refresh) ;
swipeRefreshLayout.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics()));//调整下拉控件位置
fab=(FloatingActionButton) findViewById(R.id.fab);
}
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
int childCount)
{
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager)
{
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
return true;
} else if (layoutManager instanceof StaggeredGridLayoutManager)
{
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
// StaggeredGridLayoutManager 且纵向滚动
if (orientation == StaggeredGridLayoutManager.VERTICAL)
{
childCount = childCount - childCount % spanCount;
// 如果是最后一行,则不需要绘制底部
if (pos >= childCount)
return true;
} else
// StaggeredGridLayoutManager 且横向滚动
{
// 如果是最后一行,则不需要绘制底部
if ((pos + 1) % spanCount == 0)
{
return true;
}
}
}
return false;
}
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
int childCount)
{
LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof GridLayoutManager)
{
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else if (layoutManager instanceof StaggeredGridLayoutManager)
{
int orientation = ((StaggeredGridLayoutManager) layoutManager)
.getOrientation();
if (orientation == StaggeredGridLayoutManager.VERTICAL)
{
if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
{
return true;
}
} else
{
childCount = childCount - childCount % spanCount;
if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
return true;
}
}
return false;
}
@Override
public void setupView(){
int itemSpace = (int) getResources().getDimension( R.dimen.default_padding_margin );
rvBeer.addItemDecoration( new StaggeredGridLayoutMargin( COLUMN, itemSpace ) );
StaggeredGridLayoutManager layout = new StaggeredGridLayoutManager( COLUMN, StaggeredGridLayoutManager.VERTICAL );
rvBeer.setLayoutManager( layout );
rvBeer.setAdapter( beerAdapter );
btnTryAgain.setOnClickListener( onClickTryAgain() );
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_refresh_view);
recyclerView = findViewById(R.id.recyclerView);
adapter = new ImageStageredAdapter(this);
recyclerView.setAdapter(adapter);
StaggeredGridLayoutManager staggeredGridLayoutManager =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(staggeredGridLayoutManager);
SpaceViewItemLine itemDecoration = new SpaceViewItemLine(20);
recyclerView.addItemDecoration(itemDecoration);
adapter.addHeader(new InterItemView() {
@Override
public View onCreateView(ViewGroup parent) {
BannerView header = new BannerView(SevenStaggeredActivity.this);
header.setHintView(new ColorPointHintView(SevenStaggeredActivity.this, Color.YELLOW,Color.GRAY));
header.setHintPadding(0, 0, 0, (int) AppUtils.convertDpToPixel(8, SevenStaggeredActivity.this));
header.setPlayDelay(2000);
header.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) AppUtils.convertDpToPixel(200, SevenStaggeredActivity.this)));
header.setAdapter(new BannerAdapter(SevenStaggeredActivity.this));
return header;
}
@Override
public void onBindView(View headerView) {
}
});
adapter.setMore(R.layout.view_more, new OnMoreListener() {
@Override
public void onMoreShow() {
addData();
}
@Override
public void onMoreClick() {
}
});
adapter.setNoMore(R.layout.view_nomore);
recyclerView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
adapter.clear();
adapter.addAll(DataProvider.getPictures());
}
},1000);
}
});
addData();
}
@Override
public void onCreateViewEvent(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_call_events, container, false);
setHasOptionsMenu(true);
recyclerViewCalls = (RecyclerView) rootView.findViewById(R.id.recyclerView);
callRecyclerViewAdapter = new CallRecyclerViewAdapter(getActivity(), callEvents);
recyclerViewCalls.setAdapter(callRecyclerViewAdapter);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(
getSpanCount(), StaggeredGridLayoutManager.VERTICAL);
recyclerViewCalls.setLayoutManager(layoutManager);
final RecyclerViewFragment recyclerViewFragment = this;
fab = (FloatingActionButton) rootView.findViewById(R.id.add_fab);
fab.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white)));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!PermissionHelper.isPhonePermissionAvailable(getContext())) {
new AlertDialog.Builder(getContext())
.setTitle(R.string.missing_permission)
.setMessage(R.string.missing_contacts_permission)
.setNeutralButton(R.string.close, null)
.show();
return;
}
ConfigureCallEventDialog configureCallEventDialog = new ConfigureCallEventDialog();
configureCallEventDialog.setTargetFragment(recyclerViewFragment, 0);
configureCallEventDialog.show(getFragmentManager(), null);
}
});
// BroadcastReceiver to get notifications from background service if room data has changed
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(this, "received intent: " + intent.getAction());
switch (intent.getAction()) {
case LocalBroadcastConstants.INTENT_CALL_EVENTS_CHANGED:
refreshCalls();
break;
case LocalBroadcastConstants.INTENT_PERMISSION_CHANGED:
int permissionRequestCode = intent.getIntExtra(PermissionConstants.KEY_REQUEST_CODE, 0);
int[] result = intent.getIntArrayExtra(PermissionConstants.KEY_RESULTS);
if (permissionRequestCode == PermissionConstants.REQUEST_CODE_PHONE_PERMISSION) {
boolean allGranted = true;
for (int i = 0; i < result.length; i++) {
allGranted &= result[i] == PackageManager.PERMISSION_GRANTED;
}
if (allGranted) {
StatusMessageHandler.showInfoMessage(getRecyclerView(),
R.string.permission_granted, Snackbar.LENGTH_SHORT);
sendCallEventsChangedBroadcast(context);
} else {
StatusMessageHandler.showPermissionMissingMessage(getActivity(),
getRecyclerView(),
Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_CONTACTS);
}
}
break;
}
}
};
}
public void init() {
View header = LayoutInflater.from(this).inflate(R.layout.layout_header, null);
normalAdapterManager = new BindSuperAdapterManager();
normalAdapterManager
.bind(BindImageModel.class, BindImageHolder.ID, BindImageHolder.class)
.bind(BindTextModel.class, BindTextHolder.ID, BindTextHolder.class)
.bind(BindMutliModel.class, BindMutliHolder.ID, BindMutliHolder.class)
.bind(BindClickModel.class, BindClickHolder.ID, BindClickHolder.class)
.bindEmpty(BindNoDataHolder.NoDataModel.class, BindNoDataHolder.ID, BindNoDataHolder.class)
.setNeedAnimation(true)
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(Context context, int position) {
//需要减去你的header和刷新的view的数量
Toast.makeText(context, "点击了!! " + position, Toast.LENGTH_SHORT).show();
}
})
.addHeaderView(header)
.setPullRefreshEnabled(true)
.setLoadingMoreEnabled(true)
.setFootView(new BindCustomLoadMoreFooter(this))
.setRefreshHeader(new BindCustomRefreshHeader(this))
.setLoadingListener(new OnLoadingListener() {
@Override
public void onRefresh() {
recycler.postDelayed(new Runnable() {
@Override
public void run() {
refresh();
}
}, 3000);
}
@Override
public void onLoadMore() {
recycler.postDelayed(new Runnable() {
@Override
public void run() {
loadMore();
}
}, 2000);
}
});
;
adapter = new BindSuperAdapter(this, normalAdapterManager, datas);
//瀑布流管理器
StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
//staggeredGridLayoutManager.setReverseLayout(true);
recycler.setLayoutManager(staggeredGridLayoutManager);
//使能拖拽
/*BindDragCallBack bindDragCallBack = new BindDragCallBack(adapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(bindDragCallBack);
itemTouchHelper.attachToRecyclerView(recycler);*/
//间隔线
recycler.addItemDecoration(new BindDecorationBuilder(adapter)
.setColor(getResources()
.getColor(R.color.material_deep_teal_500))
.setSpace(dip2px(this, 5))
.setNeedGridRightLeftEdge(true)
.setNeedFirstTopEdge(true)
.builder());
recycler.setAdapter(adapter);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cards);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
//check Internet Connection
new CheckInternetConnection(this).checkConnection();
//Initializing our Recyclerview
mRecyclerView = findViewById(R.id.my_recycler_view);
tv_no_item = findViewById(R.id.tv_no_cards);
if (mRecyclerView != null) {
//to enable optimization of recyclerview
mRecyclerView.setHasFixedSize(true);
}
//using staggered grid pattern in recyclerview
mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
//Say Hello to our new FirebaseUI android Element, i.e., FirebaseRecyclerAdapter
final FirebaseRecyclerAdapter<GenericProductModel,Cards.MovieViewHolder> adapter = new FirebaseRecyclerAdapter<GenericProductModel, Cards.MovieViewHolder>(
GenericProductModel.class,
R.layout.cards_cardview_layout,
Cards.MovieViewHolder.class,
//referencing the node where we want the database to store the data from our Object
mDatabaseReference.child("Products").child("Tshirt").getRef()
) {
@Override
protected void populateViewHolder(final Cards.MovieViewHolder viewHolder, final GenericProductModel model, final int position) {
if(tv_no_item.getVisibility()== View.VISIBLE){
tv_no_item.setVisibility(View.GONE);
}
viewHolder.cardname.setText(model.getCardname());
viewHolder.cardprice.setText("₹ "+Float.toString(model.getCardprice()));
Picasso.with(Tshirts.this).load(model.getCardimage()).into(viewHolder.cardimage);
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Tshirts.this,IndividualProduct.class);
intent.putExtra("product",getItem(position));
startActivity(intent);
}
});
}
};
mRecyclerView.setAdapter(adapter);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recyclerView = new RecyclerView(this);
LayoutUtil.setContentView(this, recyclerView);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
layoutManager1 = new GridLayoutManager(this, 2);
layoutManager2 = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
data.addAll(DataManager.loadData(getBaseContext()));
final CommonRcvAdapter<DemoModel> adapter = initAdapter();
wrapper = new RcvAdapterWrapper(adapter, recyclerView.getLayoutManager());
final Button header = new Button(this);
header.setText("Header\n\n (click to add)");
header.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, 300));
final Button footer = new Button(this);
footer.setText("footer");
wrapper.setHeaderView(header);
wrapper.setFooterView(null);
final Button empty = new Button(this);
empty.setBackgroundColor(Color.RED);
empty.setText("empty text");
wrapper.setEmptyView(empty, recyclerView);
recyclerView.setAdapter(wrapper);
handItemClick();
recyclerView.postDelayed(new Runnable() {
@Override
public void run() {
data.reset(DataManager.loadData(getBaseContext(),10));
wrapper.setFooterView(footer);
}
}, 1000);
}
@SuppressWarnings( "UnusedParameters" )
private void initInstance( View rootView ){
int orientation = getResources().getConfiguration().orientation;
int orientationLinear;
int orientationGrid;
int orientationStaggeredGrid;
if( orientation == Configuration.ORIENTATION_PORTRAIT ){
orientationLinear = LinearLayoutManager.VERTICAL;
orientationGrid = GridLayoutManager.VERTICAL;
orientationStaggeredGrid = StaggeredGridLayoutManager.VERTICAL;
}else{
orientationLinear = LinearLayoutManager.HORIZONTAL;
orientationGrid = GridLayoutManager.HORIZONTAL;
orientationStaggeredGrid = StaggeredGridLayoutManager.HORIZONTAL;
}
rvMargin = (RecyclerView) rootView.findViewById( R.id.rv_margin );
int itemSpace = getSpace();
int layout = getArguments().getInt( KEY_LAYOUT );
if( layout == LINEAR ){
rvMargin.removeItemDecoration( linearMargin );
LinearLayoutManager layout1 = new LinearLayoutManager( getContext(), orientationLinear, false );
rvMargin.setLayoutManager( layout1 );
linearMargin = new LayoutMarginDecoration( itemSpace );
linearMargin.setPadding( rvMargin, getMarginTop(), getMarginBottom(), getMarginLeft(), getMarginRight() );
linearMargin.setOnClickLayoutMarginItemListener( onClickItem() );
rvMargin.addItemDecoration( linearMargin );
}else if( layout == GRID ){
int gridSpan = 3;
rvMargin.removeItemDecoration( gridMargin );
rvMargin.setLayoutManager( new GridLayoutManager( getContext(), gridSpan, orientationGrid, false ) );
gridMargin = new LayoutMarginDecoration( gridSpan, itemSpace );
gridMargin.setPadding( rvMargin, getMarginTop(), getMarginBottom(), getMarginLeft(), getMarginRight() );
gridMargin.setOnClickLayoutMarginItemListener( onClickItem() );
rvMargin.addItemDecoration( gridMargin );
}else if( layout == STAGGERED_GRID ){
int stagSpan = 3;
rvMargin.removeItemDecoration( stagMargin );
rvMargin.setLayoutManager( new StaggeredGridLayoutManager( stagSpan, orientationStaggeredGrid ) );
stagMargin = new LayoutMarginDecoration( stagSpan, itemSpace );
stagMargin.setPadding( rvMargin, getMarginTop(), getMarginBottom(), getMarginLeft(), getMarginRight() );
stagMargin.setOnClickLayoutMarginItemListener( onClickItem() );
rvMargin.addItemDecoration( stagMargin );
}
rvMargin.setAdapter( new MarginAdapter( getContext() ) );
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitle("Cart");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
//check Internet Connection
new CheckInternetConnection(this).checkConnection();
//retrieve session values and display on listviews
getValues();
//SharedPreference for Cart Value
session = new UserSession(getApplicationContext());
//validating session
session.isLoggedIn();
mRecyclerView = findViewById(R.id.recyclerview);
tv_no_item = findViewById(R.id.tv_no_cards);
activitycartlist = findViewById(R.id.activity_cart_list);
emptycart = findViewById(R.id.empty_cart);
cartcollect = new ArrayList<>();
if (mRecyclerView != null) {
//to enable optimization of recyclerview
mRecyclerView.setHasFixedSize(true);
}
//using staggered grid pattern in recyclerview
mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
if(session.getCartValue()>0) {
populateRecyclerView();
}else if(session.getCartValue() == 0) {
tv_no_item.setVisibility(View.GONE);
activitycartlist.setVisibility(View.GONE);
emptycart.setVisibility(View.VISIBLE);
}
}