Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinearLayoutManager cannot resolve getOrientation()

I have a RecyclerView implemented in a fragment and I'm trying to add dividers to the code. I have the RecylcerView working as intended, but the LinearLayoutManager cannot resolve the getOrientation() function.

private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View root = (View) inflater.inflate(R.layout.fragment_settings, null);
    getActivity().setTitle("Settings");

    mRecyclerView = (RecyclerView) root.findViewById(R.id.recycler_view_settings);

    mRecyclerView.setHasFixedSize(true);

    mLayoutManager = new LinearLayoutManager(getContext());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mAdapter = new SettingsAdapter(getResources().getStringArray(R.array.setting_list));
    mRecyclerView.setAdapter(mAdapter);
    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), mLayoutManager.getOrientation());
    mRecyclerView.addItemDecoration(dividerItemDecoration);
    return root;
}
like image 840
Ryan Newquist Avatar asked Jan 09 '17 23:01

Ryan Newquist


People also ask

What is LinearLayoutManager?

LinearLayoutManager Arranges items in 1 column or 1 row based on orientation. For example, a horizontal LinearLayoutManager will place items from left to right in 1 row. GridLayoutManager Arranges items in a provided number of rows and columns, much like images in the gallery.

What is LayoutManager in Android?

A LayoutManager is responsible for measuring and positioning item views within a RecyclerView as well as determining the policy for when to recycle item views that are no longer visible to the user.

What is ViewHolder in RecyclerView Android?

A ViewHolder describes an item view and metadata about its place within the RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById results. While LayoutParams belong to the LayoutManager , ViewHolders belong to the adapter.


1 Answers

Change

private RecyclerView.LayoutManager mLayoutManager;

to

private LinearLayoutManager mLayoutManager;
like image 178
Marcin Mrugas Avatar answered Oct 08 '22 05:10

Marcin Mrugas