-1

I have a recyclerview adapter where i want to set it to portrait only. I cant seem to find any resources on this.

Is there a way to do this programatically?

can i set it in onCreateViewHolder?

public class AlarmRecyclerViewAdapter extends RecyclerView.Adapter<AlarmRecyclerViewAdapter.DataObjectHolder> {


@Override
public AlarmRecyclerViewAdapter.DataObjectHolder onCreateViewHolder(ViewGroup parent,
                                                                    int viewType) {

    AlarmRecyclerViewAdapter.DataObjectHolder dataObjectHolder = null;
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view_alarms, parent, false);
    dataObjectHolder = new AlarmRecyclerViewAdapter.DataObjectHolder(view);
    return dataObjectHolder;

}
steller
  • 205
  • 2
  • 13

3 Answers3

1

Specific views cannot request orientation. Activities can request orientation.

You can achieve as needed by adding below code in manifest:

 <activity
  android:name=".YourActivityName"
  android:screenOrientation="portrait"/>
Kruti Parekh
  • 1,261
  • 8
  • 21
Anice Jahanjoo
  • 5,438
  • 2
  • 19
  • 27
0

You can fix your activity's orientation in 2 ways:

  1. Using manifest as @nice j suggested

  2. Here is how you can set your activity's orientation programatically: link

Hope it helps

mark922
  • 1,098
  • 2
  • 11
  • 19
0

You can do this in two days,

1) In Android Manifest File

<activity
  android:name=".YourActivityName"
  android:screenOrientation="portrait"/>

2)Do it in Activity class programatically

 @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
 }
Raja Jawahar
  • 7,314
  • 8
  • 45
  • 56