I have two ListView and I want them to share the same layout position so when I click a button one ListView hides. Maybe this is not possible or there is a better way like fragments?
            Asked
            
        
        
            Active
            
        
            Viewed 917 times
        
    2 Answers
1
            Use FrameLayout. This layout view overlies two views over each other.
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/list1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
    <ListView
        android:id="@+id/list2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</FrameLayout>
For showing the first page (i.e. the first ListView):
findViewById(R.id.list1).setVisibility(View.VISIBLE);
findViewById(R.id.list2).setVisibility(View.GONE);
And for the second page:
findViewById(R.id.list1).setVisibility(View.GONE);
findViewById(R.id.list2).setVisibility(View.VISIBLE);
- 
                    Perfekt! Exactly what I was looking for. – user3800924 Dec 11 '15 at 09:06
 
1
            
            
        fragments are the easy way to do this IF you don't plan on changing the data in your views.
Make a button and
/*create fragment of the opposite view, probably through a boolean field and an if block
then*/
getSupportFragmentManager.beginTransaction().replace(/*your fragments*/).commit().
in your onclicklistener.
        Tosh
        
- 71
 - 7