I have a list but I want to make an option for the users to view it in List or Grid. The choices are in the menu. Here's the menu_user_list.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ui.user.UserListActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings" android:orderInCategory="100" app:showAsAction="never" />
<item android:id="@+id/action_listview" android:title="List" app:showAsAction="never" android:onClick="showlist" android:orderInCategory="200"/>
<item android:id="@+id/action_gridview" android:title="Grid" app:showAsAction="never" android:onClick="showgrid" android:orderInCategory="300"/>
How could I do this?
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.activity_user_list_recyclerView);
The R.id.activity_user_list_recyclerView is located on the Activity layout. It is working fine there. My main point is that how could set the menu that it will change the layout to either of the these two:
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.setLayoutManager(new LinearLayoutManager(this));
The adapter works fine. I just need to figure out how the onclick will change the layout. Thanks