0

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.

Zoker
  • 2,020
  • 5
  • 32
  • 53
  • In the answer you linked, `NestedListView` extends `ListView`... so what makes you say that "it does not [work] on `NestedListView` when the user turns his phone into landscape mode" ? – Ben P. Dec 12 '17 at 00:57
  • Ok so I set some values in the list view and on the landscape mode, they are simply not set, but in the portrait they are. In the landspace are just the default values of those fields. – Zoker Dec 12 '17 at 00:59
  • could you please edit the question to include that information? – Ben P. Dec 12 '17 at 01:09

0 Answers0