I have a list view with two textviews, one of them has its visibility set to View.GONE by default, so the listview does the wrap_content for the minimum size, the size of the listview with all the secondary textviews GONE, when I turn one of them View.VISIBLE (by clicking on the item), the height stays the same height it calculated from the very first wrap_content when it was first viewed. Tried different approaches that I read but none of them worked on my case such as
mListView.invalidate();
mListView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)mListView.getLayoutParams();
params.height = params.WRAP_CONTENT;
is there any way to force the view to recalculate the height wrap_content value after each click?
Edit1:- This is my listview layout (two is the one that is set to GONE)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/list_item_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Question?"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="8dp"
android:paddingBottom="4dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/list_item_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Answer!"
android:layout_below="@id/list_item_one"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingBottom="4dp"/>
</RelativeLayout>