Java Android Recyclerview Slide or Swipe to Right or Horizontally

Hi there. Generally, the usage of recyclerview is vertically. This following script, recyclerview is used to display list items that previously uscrolled down to horizontally or swipe to the right.

On Adapter Class create add this variable :

private RecyclerView rvItemList; 
private RecyclerView.LayoutManager layoutManager; 
private RecyclerView.Adapter adapterList;

after looping creating listData :

mContext = this; // Context

rvItemList = (RecyclerView) findViewById(R.id.rv_list); //recyclerview
rvItemList.setHasFixedSize(true); 
layoutManager = new LinearLayoutManager(mContext);
rvItemList.setLayoutManager(layoutManager);
adapterQuestions = new RvQuizFormAdapter(listData, mContext);
 
//vertical or horizontal located on this options rvItemList.setLayoutManager( 
     new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)
);
rvItemList.setAdapter(adapterQuestions);

Done !!

More discussion on comment below.

Tidak ada komentar:

Posting Komentar