Landscape - Portrait error


#1

So I have managed with the challenge of this lesson:

In QuizActivity.java:

tvAPI = (TextView)findViewById(R.id.tvAPI);
        tvAPI.setText("API level "+ Integer.toString(Build.VERSION.SDK_INT));

In activity_quiz.xml:

<TextView android:id="@+id/tvAPI" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

But when I turn my device to landscape orientation - my app crashes.
I am undersand that it because in activity_quiz.xml (land) - don’t have the same code.

But what I should to do if in portrait orientation I wonna see this TextView and in landscape orientation I don’t want to see it.

P.S.
Yes, I have my own idea about this problem.
Like to add in QuizActivity.java some checking (Display.getRotation). Perhaps there is an easier way?


#2

I have found answer by my self.

In this case you should use such construction:

  tvAPI = (TextView)findViewById(R.id.tvAPI);
        if (tvAPI != null){
            tvAPI.setText("API level "+ Integer.toString(Build.VERSION.SDK_INT));
        }