In my android app, I have a view with a different element for landscape and portrait mode. In the portrait mode, I simply use a listView like this:
<ListView
android:id="@+id/mylistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/darker_gray"
android:dividerHeight="1dp"
android:listSelector="@android:color/transparent" />
In the landscape mode I use a NestedListView (Ref: https://stackoverflow.com/a/17503823/2977288), which looks like:
<com.dev.appname.misc.NestedListView
android:id="@+id/mylistview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/darker_gray"
android:dividerHeight="1dp"
android:listSelector="@android:color/transparent" />
And then I have a code like this:
myListView = findViewById(R.id.mylistview);
While this works on the ListView (since mylistview is of class ListView), it does not on NestedListView when the user turns his phone into landscape mode.
What is the right way to fix this? Because I don't want to duplicate all my code an create a myNestedListView and do all methods again on this element.